In [28]:
import numpy as np
import pandas as pd
import seaborn as sns; sns.set(style="ticks", color_codes=True)
In [31]:
smarket=pd.read_csv('data/Smarket.csv',index_col=0)
In [32]:
smarket
Out[32]:
In [34]:
smarket.describe()
Out[34]:
In [5]:
smarket.columns
Out[5]:
In [6]:
smarket
Out[6]:
In [38]:
smarket.query("Today>=0 and Direction=='Up'")
Out[38]:
len(np.where(smarket.Direction=='Up')[0])
In [33]:
smarket
Out[33]:
In [36]:
sns.pairplot(smarket)
Out[36]:
In [44]:
import matplotlib.pyplot as pl
In [42]:
smarket.cov()
Out[42]:
In [46]:
sns.heatmap(smarket.cov())
Out[46]:
In [48]:
smarket.cov()
Out[48]:
In [67]:
X=smarket.iloc[:,1:-1]
Y=smarket.iloc[:,-1]
Logistic Regression¶
In [82]:
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import classification_report, confusion_matrix
import statsmodels.api as sm
In [146]:
model = LogisticRegression(solver='liblinear', random_state=0)
In [147]:
model.fit(X,Y)
Out[147]:
In [148]:
model.intercept_
Out[148]:
In [77]:
model.coef_
Out[77]:
In [150]:
y_hat=model.predict(X)
In [153]:
confusion_matrix(Y,y_hat)
Out[153]:
In [155]:
report=classification_report(Y,y_hat)
print('report:', report, sep='\n')
In [134]:
Y_dummy=np.zeros([Y.size,1])
Y_dummy[np.where(Y=='Up')]=1
In [135]:
model=sm.Logit(Y_dummy,X.values)
In [141]:
result=model.fit(method='newton', maxiter=100)
In [145]:
result.summary2()
Out[145]:
In [125]:
X.values.shape
Out[125]:
In [ ]:
No comments:
Post a Comment