Prediction
Once we've trained our module, it's time to think about test data evaluation and future predictions. We can make predictions using the method predict().
Let's look at an example. Prediction for flavanoids when the number of total phenols is 1:
12new_total_phenols = np.array([1]).reshape(-1,1) print(model.predict(new_total_phenols))
Output:
[2.06352084]
Method
.reshape()gives a new shape to an array without changing its data. Input must be a 2-dimension (DataFrame or 2-dimension array will work here).
This value is the same as if we had substituted the line b + kx, where b is the estimated intersection with the model, and k is the slope. Please note that we multiply by 1 since the number of total phenols is 1 (x = 1).
1prediction = model.intercept_ + model.coef_*1
We can also put our testing data to get predictions for all amounts of flavanoids:
1y_test_predicted = model.predict(X_test)
Swipe to start coding
Predict with the previous split-train data the amount of flavanoids if the total phenols is 2.
- [Line #6] Import the
numpylibrary. - [Line #26] Initialize the linear regression model.
- [Line #30] Assign
np.array()and number of total phenols as the parameter (2) to the variablenew_total_phenols(don’t forget to use the function.reshape(-1,1)). - [Line #31] Predict amount of flavanoids
- [Line #32] Print the predicted amount of flavanoids.
Løsning
Takk for tilbakemeldingene dine!
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Oppsummer dette kapittelet
Explain code
Explain why doesn't solve task
Awesome!
Completion rate improved to 4.76
Prediction
Sveip for å vise menyen
Once we've trained our module, it's time to think about test data evaluation and future predictions. We can make predictions using the method predict().
Let's look at an example. Prediction for flavanoids when the number of total phenols is 1:
12new_total_phenols = np.array([1]).reshape(-1,1) print(model.predict(new_total_phenols))
Output:
[2.06352084]
Method
.reshape()gives a new shape to an array without changing its data. Input must be a 2-dimension (DataFrame or 2-dimension array will work here).
This value is the same as if we had substituted the line b + kx, where b is the estimated intersection with the model, and k is the slope. Please note that we multiply by 1 since the number of total phenols is 1 (x = 1).
1prediction = model.intercept_ + model.coef_*1
We can also put our testing data to get predictions for all amounts of flavanoids:
1y_test_predicted = model.predict(X_test)
Swipe to start coding
Predict with the previous split-train data the amount of flavanoids if the total phenols is 2.
- [Line #6] Import the
numpylibrary. - [Line #26] Initialize the linear regression model.
- [Line #30] Assign
np.array()and number of total phenols as the parameter (2) to the variablenew_total_phenols(don’t forget to use the function.reshape(-1,1)). - [Line #31] Predict amount of flavanoids
- [Line #32] Print the predicted amount of flavanoids.
Løsning
Takk for tilbakemeldingene dine!
single