Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incomplete code for Exercise 2 (Logistic Regression), Regularization #110

Open
Official-Dev-long opened this issue Nov 9, 2023 · 4 comments

Comments

@Official-Dev-long
Copy link

According to the requirements of the exercise, the polynomial terms should be up to sixth power, which mean transformed into a 28-dimensional vector, but the code provided only consists 11 dimension. I found that this error occurs due to these code (generating polynomials) in the original script:

degree = 5
x1 = data2['Test 1']
x2 = data2['Test 2']

data2.insert(3, 'Ones', 1)

for i in range(1, degree):
    for j in range(0, i):
        data2['F' + str(i) + str(j)] = np.power(x1, i-j) * np.power(x2, j)

data2.drop('Test 1', axis=1, inplace=True)
data2.drop('Test 2', axis=1, inplace=True)

data2.head()

here I provided my code which could generate the right 28-dimensional vector, which higher the accuracy up to 83.05% (using sklearn package), while original code provided only hit 66.10% when only 11-d vector used as input

max_degree = 6

x1 = data2['Test 1'] 
x2 = data2['Test 2']

for i in range(2, max_degree + 1):
    for j in range(i+1):
        data2['x1^' + str(i-j) + '_x2^' + str(j)] = np.power(x1, i-j) * np.power(x2, j)
data2

the result of my code also more readable, here is the column of the data after generated the 28-d vector:

data.columns

Index(['Ones', 'Test 1', 'Test 2', 'Accepted', 'x1^2_x2^0', 'x1^1_x2^1',
'x1^0_x2^2', 'x1^3_x2^0', 'x1^2_x2^1', 'x1^1_x2^2', 'x1^0_x2^3',
'x1^4_x2^0', 'x1^3_x2^1', 'x1^2_x2^2', 'x1^1_x2^3', 'x1^0_x2^4',
'x1^5_x2^0', 'x1^4_x2^1', 'x1^3_x2^2', 'x1^2_x2^3', 'x1^1_x2^4',
'x1^0_x2^5', 'x1^6_x2^0', 'x1^5_x2^1', 'x1^4_x2^2', 'x1^3_x2^3',
'x1^2_x2^4', 'x1^1_x2^5', 'x1^0_x2^6'],
dtype='object')

@xiadongdong
Copy link

xiadongdong commented Nov 9, 2023 via email

@sullinger
Copy link

sullinger commented Nov 9, 2023 via email

@yanyiting
Copy link

yanyiting commented Nov 9, 2023 via email

@Enya191113
Copy link

Enya191113 commented Nov 9, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants