1#Logistic Regression Model
2
3from sklearn.linear_model import LogisticRegression
4LR = LogisticRegression(random_state=0).fit(X, y)
5LR.predict(X[:2, :]) #Return the predictions
6LR.score(X, y) #Return the mean accuracy on the given test data and labels
7
8#Regression Metrics
9#Mean Absolute Error
10
11from sklearn.metrics import mean_absolute_error
12mean_absolute_error(y_true, y_pred)
13
14#Mean Squared Error
15
16from sklearn.metrics import mean_squared_error
17mean_squared_error(y_true, p_pred)
18
19#R2 Score
20
21from sklearn.metrics import r2_score
22r2_score(y_true, y_pred)
1# import the class
2from sklearn.linear_model import LogisticRegression
3
4# instantiate the model (using the default parameters)
5logreg = LogisticRegression()
6
7# fit the model with data
8logreg.fit(X_train,y_train)
9
10#
11y_pred=logreg.predict(X_test)
12
1model1 = LogisticRegression(random_state=0, multi_class='multinomial', penalty='none', solver='newton-cg').fit(X_train, y_train)
2preds = model1.predict(X_test)
3
4#print the tunable parameters (They were not tuned in this example, everything kept as default)
5params = model1.get_params()
6print(params)
7
8{'C': 1.0, 'class_weight': None, 'dual': False, 'fit_intercept': True, 'intercept_scaling': 1, 'l1_ratio': None, 'max_iter': 100, 'multi_class': 'multinomial', 'n_jobs': None, 'penalty': 'none', 'random_state': 0, 'solver': 'newton-cg', 'tol': 0.0001, 'verbose': 0, 'warm_start': False}
1# import the metrics class
2from sklearn import metrics
3cnf_matrix = metrics.confusion_matrix(y_test, y_pred)
4cnf_matrix
5