Last answered:

09 Apr 2024

Posted on:

06 Apr 2024

0

reg.predict(new_data) has a warning.

 What does this warning mean? I recieved the result properly (the table contains Predicted_GPA).


4 answers ( 0 marked as helpful)
Instructor
Posted on:

08 Apr 2024

0

Hey Natchanok,


Thank you for reaching out!


Could you please adjust your code based on the following comment:

https://365datascience.com/q/4470918713


Let me know if the problem persists and you need further assistance.


Kind regards,

365 Hristina

Posted on:

08 Apr 2024

0

Hi @Hristina


This is not the issue with the input is not matrix.


the new data is already a matrix

Posted on:

08 Apr 2024

0

The output is return correctly for prediction of GPA from 2 values of SAT. but dont know why I recieve this warning about feature names.

Instructor
Posted on:

09 Apr 2024

0

Hey again Natchanok,


Let's break down the error message to address the issue more effectively.


The error message you're seeing is:

X does not have valid feature names, but LinearRegression was fitted with feature names

To dissect this, let's look at the second part: 'LinearRegression was fitted with feature names.' This means that when you used reg.fit(x, y), your x variable had an associated feature name, specifically 'SAT'.



Conversely, the error's first part, 'X does not have valid feature names,' indicates that the feature you're trying to use in reg.predict(...) lacks feature names, leading to the discrepancy. In the example below, the feature 1740 isn't associated with a corresponding feature name:


In contrast, this code snippet functions correctly as it includes the feature name 'SAT':


Thus, ensure your new_data variable is a DataFrame with proper feature names. This adjustment should resolve the error you're encountering.


If you have any more questions or require additional assistance, please don't hesitate to reach out.


Kind regards,

365 Hristina 

Submit an answer