(Caution: The author does not specialize in this field, so there may be lack of explanation or mistakes.) This article messes up the discussion of implementing simple regression analysis in Keras. Jupyter Notebook will be published on GitHub, so you can try it immediately if you have an environment. For simple regression analysis, we refer to Udemy's [Kikagaku style] artificial intelligence / machine learning de-black box course-beginner's edition-. Those who want to see detailed explanations are recommended to attend. [Kikagaku style] Artificial intelligence / machine learning de-black box course-Beginner- https://www.udemy.com/course/kikagaku_blackbox_1/learn/lecture/8258758#overview
Click here for notebook Run SimpleRegressionAnalysis_2.ipynb. The execution environment etc. are described at the beginning of the notebook. https://github.com/moriitkys/SimpleRegressionAnalysis
The explanation of simple regression analysis is summarized as follows in an easy-to-understand manner. "One objective variable is predicted by one explanatory variable, and the relationship between the two variables is expressed in the form of a linear equation Y = aX + b. If a (slope) and b (y-intercept) are known, , Y (weight) can be predicted from X (height) " https://www.albert2005.co.jp/knowledge/statistics_analysis/multivariate_analysis/single_regression
Also, this page explains in detail. Thorough explanation of regression analysis (simple regression analysis) in an easy-to-understand manner! https://udemy.benesse.co.jp/ai/regression-analysis.html
Below is a diagram of what to do this time.
Simple regression analysis is performed using a library for neural networks called Keras. It is written in Python and can be executed on Tensorflow. This time it's a simple regression analysis Model creation: model=Sequential() model.add() (Caution: Does not activate) Model initialization model.init() Start learning the model model.fit() Model guess model.prediction() It becomes a flow like. The code is this part.
SimpleRegressionAnalysis.ipynb
# Build model
model = Sequential()
model.add(Dense(1, input_shape=(s, ), use_bias=False))
opt = keras.optimizers.Adam(lr=0.04, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.0003)
model.compile(optimizer=opt,
loss='mean_squared_error',
metrics=['mae'])
# Start training
history = model.fit(x_normalized, y_normalized, epochs=50, batch_size=20, verbose=1)
It has the following simple form.
Therefore, the result of model.summary () also has one parameter.
If it becomes a multiple regression analysis, it will look like the following.
As a result of learning, the loss value changed as follows, and it seems that it was fitted immediately. The number of epochs is on the horizontal axis.
The model of the result of finding a by modeling by calculation, setting and minimizing the evaluation function, and the result of finding the model by Keras are as follows.
The points plotted in green are the results of guessing by inputting the 98th to 108th RMs of the house price data set into the model of the simple regression analysis created this time. Since it is a straight line model, you can see that it is guessed on the straight line. By the way, when using Keras, I set the data in the range of 0 to 1, but be careful because you can not learn if you enter it normally (you can not learn with this notebook method). Therefore, the value of a is also very different from the one calculated by the formula, but it seems that both are fitted to the data in the same way.
In order not to forget the original intention, I put a rewrite of the data reading in pandas with a for loop in SimpleRegressionAnalysis_3.ipynb. If you're just starting machine learning and don't know what you're doing here, just for reference.
SimpleRegressionAnalysis_3.ipynb
with open('boston.csv') as f:
reader = csv.reader(f)
for row in reader:
x_orig.append(row[6])
y_orig.append(row[14])
It is like this. Articles may be updated.
reference https://matplotlib.org/ https://matplotlib.org/3.2.1/api/_as_gen/matplotlib.pyplot.subplot.html https://pandas.pydata.org/pandas-docs/stable/reference/frame.html https://scikit-learn.org/stable/ https://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_boston.html#sklearn.datasets.load_boston https://seaborn.pydata.org/ https://keras.rstudio.com/articles/tutorial_basic_regression.html https://www.kaggle.com/xgdbigdata/keras-regression-tutorial https://github.com/KatsuhiroMorishita/machine_leaning_samples https://www.udemy.com/course/kikagaku_blackbox_1/learn/lecture/8258758#overview