-3

I have a model that I have trained and visualized, the problem is that I can't seem to find a way to graph the curve onto my plot

%matplotlib inline
import pandas as pd
from matplotlib import pyplot as plt

log_df = pd.read_csv("datalist/education/pollingData.csv")

enter image description here

X_train, X_test, y_train, y_test = train_test_split(log_df[['PercentYes']],log_df.side_val,test_size=0.2)

from sklearn.linear_model import LogisticRegression
model = LogisticRegression()
model.fit(X_train, y_train)
Y = model.predict(X_test)

plt.figure(1, figsize=(4, 3))
plt.clf()
plt.scatter(X_train, y_train, color="black", marker='+')
plt.plot(X_train, y, color='red')

If I add the last line of code I get an error saying:

ValueError: x and y must have same first dimension, but have shapes (40, 1) and (10,)

Without that last line I just get a graph with no s curve, how would I go about reshaping the dimensions of my x and y values

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Karthik
  • 7
  • 4
  • **[Don't Post Screenshots](https://meta.stackoverflow.com/questions/303812/)**. This question needs a [SSCCE](http://sscce.org/). Always provide a [mre], with **code, data, errors, current output, and expected output, as [formatted text](https://stackoverflow.com/help/formatting)**. It's likely the question will be down-voted and closed. You're discouraging assistance, as no one wants to retype data/code, and screenshots are often illegible. [edit] the question and **add text**. Plots are okay. See [How to provide a reproducible dataframe](https://stackoverflow.com/questions/52413246). – Trenton McKinney Nov 03 '21 at 11:11
  • 1
    As shown in the answer `plt.plot(X_train, Y, color='red')` should be `X_test` since `Y` is generated with `X_test`. This is more of a typo and should be flagged in a comment and then voted to close as caused by a typo / not reproducible. – Trenton McKinney Nov 03 '21 at 11:14

1 Answers1

0

If you want to plot the prediction on test set, you need to set X_test at first argument:

y = model.predict(X_test)
plt.plot(X_test, y, color='red')
Valentin Goldité
  • 1,040
  • 4
  • 13