![]() ![]() Then, create a new model using LinearRegression(), lets say model = LinearRegression().First, import the LinearRegression from the sklearn.linear_model sub-module.The steps to create a model and get the best fit line parameters are as follows: We can use the pre-defined linear regression model in sklearn librery’s/module’s linear_model sub-module to get the best fit line for the given data points. So, let’s do another method to get the best fit line. We have already discussed two different methods, for getting the best fit line to scatter. Read: Matplotlib plot a line Matplotlib best fit line to scatter Plt.title('2nd degree best fit curve using numpy.polyfit()') # Plotting the data points and the best fit 2nd degree curve Y_line = theta + theta * pow(X, 1) + theta * pow(X, 2) # the parameters theta0, theta1 and theta2 # Now, calculating the y-axis values against x-values according to ![]() # Calculating the parameters using the least square method # Preparing X and y data from the given data # Preparing the data to be computed and plotted Now, let’s implement this algorithm using python and plot the resulted line. X) -1 is the inverse of the resulted matrix from (X T. y) Here, X T is the transpose of the matrix X, and (X T. We can calculate and get the optimal parameter values (theta0 and theta1) for the given data points by using the least square method equation in vector form, that is as follows: Now, the equation in vector form will be like this: y = X.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |