Linear Regression
Here we initialise and train a Linear Regression model before using the model to make predictions. Finally we find the intercept and cofficients of the model along with analysing the models performance on test data using mean squared error and mean absolute error metrics.
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
print(model.intercept_)
coef = pd.DataFrame(model.coef_, X_train.columns, columns=['Coef'])
from sklearn.metrics import mean_squared_error, mean_absolute_error
print('MSE:',mean_squared_error(y_test,y_pred))
print('MAE:',mean_absolute_error(y_test,y_pred))
For more detail, see the Scikit-Learn documentation here
Logistic Regression
Here we initialise and train a Logistic Regression model before using the model to make predictions. Finally we find the intercept and cofficients of the model along with analysing the models performance on test data using the Classification Report.
from sklearn.linear_model import LogisticRegression
model = LogisticRegression()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
print('Intercept:',model.intercept_)
coef = pd.DataFrame(model.coef_.reshape(30,1), cols, columns=['Coefficients'])
print(coef)
from sklearn.metrics import classification_report
print(classification_report(y_test, y_pred))
For more detail, see the Scikit-Learn documentation here