Make a one-element volume table, if you don’t understand forestry, you may not know it, as shown in the figure, that is, the relationship between the structure volume and the diameter at breast height. Python's unary linear regression method is used here (I used spss to do a power function nonlinear regression, the effect is the best ).

- Import library and data

from sklearn import linear_model import numpy as np import pandas as pd import matplotlib.pyplot as plt df1 = pd.read_excel('C:/Users/Administrator/Desktop/One yuan volume table.xlsx')

- Draw a scatter plot

X = np.array(df1[['Breast Diameter']]) Y = np.array(df1[['量']]) plt.rc('font',family='STXihei',size=15) plt.scatter(X,Y,60,color='blue',marker='o',linewidths=3,alpha=0.4) plt.xlabel('Diameter at breast height') plt.ylabel('Volume') plt.title('One yuan volume table') plt.show()

It can be seen that using one-variable linear regression is not ideal, but in order to hand in homework to the teacher, it is better to do it.

- Unary regression model

clf = linear_model.LinearRegression() clf.fit(X,Y) print(clf.coef_,clf.intercept_) print(clf.score(X,Y))

The result is shown in the figure

R2 is not high, and the model is not very good.

Reference: https://cloud.tencent.com/developer/article/1155570 Python data analysis one-element linear regression problem Python variance analysis conclusions-Cloud + Community-Tencent Cloud