[Python] How to calculate the approximation formula of the same intercept 0 as Excel [scikit-learn] Memo

Overview

For Excel

For Python

pandas+scikit-learn


from sklearn.linear_model import Ridge,LinearRegression
from sklearn.preprocessing import PolynomialFeatures
from sklearn.pipeline import make_pipeline

#Create the same data as Excel
x=np.array([0,3,12.5,18.7,25,20,16,12.8,10.24,8.192])
y=np.array([0,15,46.6,60.3,74.3,59.44,47.552,46,36.8,29.44])

#DEGREE (order)
degree = 3

# LinearRegression
# make_Gacchanko Polynomial Features and Linea Regression on pipeline
model = make_pipeline(PolynomialFeatures(degree,include_bias=False),LinearRegression(fit_intercept=False))
model.fit(x.reshape(-1,1),y)
y_model=model.predict(x.reshape(-1,1))

#Check data frame
df = pd.DataFrame({'y_model.predict':y_model,},index=x)
df.sort_index().plot(kind ='line',figsize=(10.,5.))

#coefficient
model.steps[1][1].coef_
array([ 5.06817229e+00, -1.71343566e-01,  3.49200227e-03])

Summary

Recommended Posts

[Python] How to calculate the approximation formula of the same intercept 0 as Excel [scikit-learn] Memo
How to calculate the volatility of a brand
How to get a list of files in the same directory with python
How to get the number of digits in Python
How to visualize the decision tree model of scikit-learn
[Python] Summary of how to specify the color of the figure
How to calculate the amount of calculation learned from ABC134-D
How to develop in a virtual environment of Python [Memo]
How to check if the contents of the dictionary are the same in Python by hash value
How to handle multiple versions of CUDA in the same environment
How to change the log level of Azure SDK for Python
How to know the internal structure of an object in Python
How to check the memory size of a variable in Python
Calculate the editing distance as an index of pronunciation similarity [python]
[Python] How to get the first and last days of the month
How to get the Python version
How to check the memory size of a dictionary in Python
[Python] How to import the library
How to calculate date with python
How to update the python version of Cloud Shell on GCP
[Nanonets] How to post Memo [Python]
Get the formula in an excel file as a string in Python
[Beginner memo] How to specify the library reading path in Python
How to display bytes in the same way in Java and Python
[Python] How to specify the window display position and size of matplotlib
How to crop the lower right part of the image with Python OpenCV
[Introduction to Python] How to sort the contents of a list efficiently with list sort
How to compare if the contents of the objects in scipy.sparse.csr_matrix are the same
[Python] How to open two or more files at the same time
[Python] Summary of how to use pandas
How to check the version of Django
How to install CatBoost [as of January 2020]
How to calculate Use% of df command
[Python2.7] Summary of how to use unittest
[Python] How to calculate MAE and RMSE
Summary of how to use Python list
[Python2.7] Summary of how to use subprocess
[Question] How to use plot_surface of python
How to pass the execution result of a shell command in a list in Python
[Circuit x Python] How to find the transfer function of a circuit using Lcapy
[python] How to sort by the Nth Mth element of a multidimensional array
[Numpy, scipy] How to calculate the square root of a semi-fixed definite matrix
How to find the coefficient of the trendline that passes through the vertices in Python
Note: How to get the last day of the month with python (added the first day of the month)
Python C / C ++ Extensions: Pass some of the data as np.array to Python (set stride)
[Introduction to Python] How to get the index of data with a for statement
How to use the C library in Python
[Python] How to use two types of type ()
Convert "number" of excel date to python datetime
[Python] How to change the date format (display format)
Summary of how to import files in Python 3
Calculate the total number of combinations with python
[Python] How to read excel file with pandas
How to read original data or external data on the Internet with scikit-learn instead of attached data set such as iris
Summary of how to use MNIST in Python
How to specify attributes with Mock of python
Excel X Python The fastest way to work
[Algorithm x Python] How to use the list
How to erase the characters output by Python
How to get dictionary type elements of Python 2.7
How to get the files in the [Python] folder