Time：2019-8-13

# linear regression

Linear RegressionIt is a statistical analysis method to determine the interdependent quantitative relationship between two or more variables by using regression analysis in mathematical statistics.

## Simple Linear Regression (Univariate Linear Regression)

Find a straight line, the minimum sum of the distance from the line to each point ==> least square method (junior high school)

``````import matplotlib.pyplot as plt
import numpy as np
from sklearn.linear_model import LinearRegression
### Distance km
x = [3.4, 1.8, 4.6, 2.3, 3.1, 5.5, 0.7, 3.0, 2.6, 4.3, 2.1, 1.1, 6.1, 4.8, 3.8]
### Price
y = [26.2, 17.8, 31.3, 23.1, 27.5, 36.0, 14.1, 22.3, 19.6, 31.3, 24.0, 17.3, 43.2, 36.4, 26.1]
x_in = np.array(x).reshape(-1,1)
y_in = np.array(y).reshape(-1,1)
lreg = LinearRegression()
result = lreg.fit(x_in, y_in)
b1 = result.coef_[0][0]
b0 = result.intercept_[0]
print(b1)
print(b0)
y_prd = lreg.predict(x_in)
# scatter plot
plt.scatter(x, y)
plt.plot(x_in,y_prd,'m')
plt.xlabel("km")
plt.ylabel("rmb")
plt.title("price")
plt.show()``````

## multiple linear regression

``````import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
from sklearn.linear_model import LinearRegression

x = [[100,4],[50,3],[100,4],[100,2],[50,2],[80,2],[75,3],[65,4],[90,3],[90,2]]
y = [9.3,4.8,8.9,6.5,4.2,6.2,7.4,6.0,7.6,6.1]

x = np.array(x)
y = np.array(y)
lreg = LinearRegression()
result = lreg.fit(x, y)
# Weight value
b1 = result.coef_[0][0]
# Bias value
b0 = result.intercept_[0]
print(b1)
print(b0)``````

## The method of obtaining the resolution of display by pyqt5

The code is as follows import sys from PyQt5.QtWidgets import QApplication, QWidget class Example(QWidget): def __init__(self): super().__init__() self.initUI() #Interface drawing to initui method def initUI(self): self.desktop = QApplication.desktop() #Get display resolution size self.screenRect = self.desktop.screenGeometry() self.height = self.screenRect.height() self.width = self.screenRect.width() print(self.height) print(self.width) #Show window self.show() if __name__ == ‘__main__’: #Create applications and objects app […]