sklearn-linear regression Flashcards

1
Q

create an instance of linear regression

A

reg = LinearRegression()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

fit linear regression model

A

reg.fit(x_matrix,y)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

calculate R-squred for linear regression

A

reg.score(x_matrix,y)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

find intercept

A

reg.intercept_

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

find coefficient

A

reg.coef_

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

make prediction for new_data. new_data is one-dimensional

A

reg.predict([[new_data]])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what you need to do if x is one dimensional ? give the code.

A

It needs to be a two-dimensional matrix.

x_matrix = x.values.reshape(-1,1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

feature selection. code and its output?

A

f_regression(x,y)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

obtain pvalue from feature selection

A

p_values = f_regression(x,y)[1].round(3)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Create a StandardScaler instance

A

scaler = StandardScaler()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

fit feature x to scaler/calculate the mean and std

A

scaler.fit(x)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

create a new variable for feature x with raw data scaled

A

x_scaled = scaler.transform(x)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly