Skip to content

Instantly share code, notes, and snippets.

@Lanse505
Created December 14, 2022 22:10
Show Gist options
  • Save Lanse505/9ed83c7442af679f1c641632531c0ace to your computer and use it in GitHub Desktop.
Save Lanse505/9ed83c7442af679f1c641632531c0ace to your computer and use it in GitHub Desktop.
from sklearn.naive_bayes import GaussianNB
x = beandata['MajorAxisLength'].to_numpy().reshape(-1, 1)
dummy = pd.get_dummies(beandata['Class'].values)
y = dummy['BOMBAY'].values
model = GaussianNB().fit(x, y)
y_pred = model.predict(x)
fig, ax = plt.subplots(figsize=(16, 8))
fig.suptitle('Regression Line of GNB')
ax.yaxis.set_ticks((0, 1))
# Using my predicted and modeled curve.
ax.scatter(x, y, color='Blue')
#ax.plot(x, y_pred, color='Red')
ax.set_ylim(-0.05, 1.05)
sns.regplot(x=x, y=y_pred, order=4, ax=ax, scatter_kws={"color": 'Blue'}, line_kws={"color": 'Red'}, ci=None)
from sklearn.linear_model import LogisticRegression
# Import and setup our data.
x = beandata['MajorAxisLength'].to_numpy().reshape(-1, 1)
dummy = pd.get_dummies(beandata['Class'].values)
y = dummy['BOMBAY'].values
# Create out LogisticRegression Model.
# Uses the liblinear solver and a set random_state.
model = LogisticRegression(solver='liblinear', random_state=123).fit(x, y)
y_pred = model.predict(x)
# Set up the Sub-Plot Figure.
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(16,8))
# Set up Figure Specs.
fig.suptitle('Regression Line of LogisticRegression')
fig.supxlabel('MajorAxisLength')
fig.supylabel('Found Class')
# Set up Sub-Plot Specs.
ax1.yaxis.set_ticks((0, 1))
ax2.yaxis.set_ticks((0, 1))
# Using my predicted and modeled curve.
ax1.scatter(x, y, color='Blue')
ax1.set_ylim(-0.05, 1.05)
sns.regplot(x=x, y=y_pred, order=7, ax=ax1, scatter_kws={"color": 'Blue'}, line_kws={"color": 'Red'}, ci=None)
# Using the built-in logistic regression from Seaborn.
sns.regplot(x=x, y=y, logistic=True, ax=ax2, scatter_kws={"color": 'Blue'}, line_kws={"color": 'Red'}, ci=None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment