sklearn-linear regression Flashcards
create an instance of linear regression
reg = LinearRegression()
fit linear regression model
reg.fit(x_matrix,y)
calculate R-squred for linear regression
reg.score(x_matrix,y)
find intercept
reg.intercept_
find coefficient
reg.coef_
make prediction for new_data. new_data is one-dimensional
reg.predict([[new_data]])
what you need to do if x is one dimensional ? give the code.
It needs to be a two-dimensional matrix.
x_matrix = x.values.reshape(-1,1)
feature selection. code and its output?
f_regression(x,y)
obtain pvalue from feature selection
p_values = f_regression(x,y)[1].round(3)
Create a StandardScaler instance
scaler = StandardScaler()
fit feature x to scaler/calculate the mean and std
scaler.fit(x)
create a new variable for feature x with raw data scaled
x_scaled = scaler.transform(x)