plots2 Flashcards
seaborn distribution plot
sns.distplot(df[‘col’])
3 scatter plots side by side horizontally sharing the y axis.
f, (ax1, ax2, ax3) = plt.subplots(1, 3, sharey=True, figsize =(15,3))
ax1. scatter(df[‘col1’],df[‘value’])
ax1. set_title(‘value and col1’)
ax2. scatter(df[‘col2’],df[‘value’])
ax2. set_title(‘value and col2’)
ax3. scatter(df[‘col3’],df[‘value’])
ax3. set_title(‘value and col3’)
plt.show()
scatter plot after linear regression model is trained to compare the prediction and the target
y_hat = reg.predict(x_train)
plt. scatter(y_train, y_hat)
plt. xlabel(‘Targets (y_train)’,size=18)
plt. ylabel(‘Predictions (y_hat)’,size=18)
plt. xlim(min(y_train),max(y_train))
plt. ylim(min(y_train),max(y_train))
plt. show()
residual plot after regression model is trained
sns. distplot(y_train - y_hat)
plt. title(“Residuals PDF”, size=18)
plot logistic regression
reg_log = sm.Logit(y,x) results_log = reg_log.fit()
def f(x,b0,b1): return np.array(np.exp(b0+x*b1) / (1 + np.exp(b0+x*b1)))
# Sorting the y and x, so we can plot the curve f_sorted = np.sort(f(x1,results_log.params[0],results_log.params[1])) x_sorted = np.sort(np.array(x1)) ax = plt.scatter(x1,y,color='C0') plt.xlabel('X', fontsize = 20) plt.ylabel('Target', fontsize = 20) ax2 = plt.plot(x_sorted,f_sorted,color='red') plt.figure(figsize=(20,20)) plt.show()