Logistic Regression Using Python
Logistic Regression Using Python
0 1 62.00 270000
1 2 76.33 200000
2 3 72.00 240000
3 4 60.00 250000
4 5 61.00 180000
<matplotlib.collections.PathCollection at 0x26fcab243d0>
Out[85]:
In [ ]:
In [ ]:
In [86]: data.mean()
In [87]: data.mode()
0 68.0 300000
In [88]: data.median()
In [89]: data.std()
In [91]: data.quantile(q=0.25)
In [92]: data.quantile(q=[0.25,0.5])
In [93]: data.var()
LOGISTIC REGRESSION
In [151… # Import necessary libraries
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, classification_report, f1_score
Accuracy: 1.00
f1 score: 1.0
Classification Report:
precision recall f1-score support
accuracy 1.00 2
macro avg 1.00 1.00 1.00 2
weighted avg 1.00 1.00 1.00 2
In [ ]:
In [ ]:
In [ ]:
In [ ]:
MULTINOMIAL REGRESSION
In [115… # Import necessary libraries
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, classification_report
Dataset:
Hours_Studied Hours_Slept Grade
0 2 5 F
1 3 6 F
2 4 5 F
3 5 7 C
4 6 8 B
5 7 7 C
6 8 8 B
7 9 9 A
8 10 10 A
Accuracy: 1.00
Classification Report:
precision recall f1-score support
accuracy 1.00 2
macro avg 1.00 1.00 1.00 2
weighted avg 1.00 1.00 1.00 2
Dataset:
Hours_Studied Hours_Slept Score
0 2 5 55
1 3 6 65
2 4 5 50
3 5 7 80
4 6 8 90
5 7 7 75
6 8 8 85
7 9 9 95
8 10 10 100
Coefficients:
[-2.43842365 13.36206897]
Intercept: -4.384236453201979
mlr = sm.OLS(n,m).fit()
print("Params:")
print(mlr.params)
y_pred = mlr.predict(m)
print('Y Pred: ')
print(y_pred)
0.9706465820573179
In [143… mlr.summary2()
C:\Users\Ishant\anaconda3\Lib\site-packages\scipy\stats\_stats_py.py:1736: UserWar
ning: kurtosistest only valid for n>=20 ... continuing anyway, n=9
warnings.warn("kurtosistest only valid for n>=20 ... continuing "
Notes:
[1] R² is computed without centering (uncentered) since the model does not contain a
constant.
[2] Standard Errors assume that the covariance matrix of the errors is correctly specified.
In [ ]:
array([[ 7],
Out[107]:
[ 7],
[ 2],
[ 5],
[10],
[10],
[ 4],
[ 5],
[ 6],
[ 8],
[ 5],
[ 7],
[ 8],
[ 8]], dtype=int64)
0 2 5 0
1 3 6 0
2 4 5 0
3 5 7 0
4 6 8 1
5 7 7 1
6 8 8 1
7 9 9 1
8 10 10 1
In [165…
In [ ]:
In [ ]:
In [ ]:
In [ ]: