Last answered:

19 Jun 2024

Posted on:

06 Apr 2024

1

reg.predict(new_data) has a warning.

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


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

08 Apr 2024

1

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 

Posted on:

15 Jun 2024

0

I don't think that solved the problem, also it lookes like the DataFrame already does have the header (column name) in line 34. Please help?  

Instructor
Posted on:

17 Jun 2024

1

Hey Chrisant,


Thank you for reaching out!


It seems like the problem you encounter is the opposite one - you have fitted the Linear Regression with a data that doesn't have feature names. However, the data you use to predict values (new_data) has feature names.


Make sure that either:

- both datasets have feature names or

- both datasets don't have feature names.


Let me know if the issue persists.


Kind regards,

365 Hristina

Posted on:

19 Jun 2024

1

Thanks! I solved this by making new_data into a dataframe.

new_data_scaled = scaler.transform(new_data)
new_data_scaled_df = pd.DataFrame(new_data_scaled,columns=['SAT','Rand 1,2,3'])

Submit an answer