Machine learning (--regularization:regularized) Linear regression
Gradient descent
Without regularization
With regularization
Θ0 is the same as the original, no regularization.
The θ1-n is slightly smaller than the original (1-αλ⁄m)
Normal equation
Witho
# Linear regression least squaresFrom Sklearn import Linear_modelImport SysImport Tushare as TSImport Matplotlib.pyplot as PltImport Pandas as PDImport Sklearn.metrics as SMSh=ts.get_hist_data (' sh '). Sort_index () #获取上证指数每日数据 and sorted by time indexPf=ts.get_hist_data (' 600000 '). Sort_index () #获取浦发银行数据 and sorted by time indexsh[' re ']=np.log (sh[' close ']/sh[' Close '].shift (1)) #计算上证指数收益率pf[' re
(https://mirrors.tuna.tsinghua.edu.cn/CRAN/) After download good R open, you can enter the command, as below, I enter> Y=c (61,57,58,40,90,35,68) indicates that a y vector is created, and the value of the vector is the content after C> y echo y[1] 61 57 58 40 90 35 68> X=c (170,168,175,153,185,135,172) create an x vector> x Echo X[1] 170 168 175 153 185 135 172>> Plot (x, y), y to the left ordinate, and scatter plot.> Z=lm (y~x+1) a linear
In this lesson, we talk about the example of the regression of the downline, and introduce several common optimization algorithms.
After the linear fitting of the data, it is found that the error is large, so Huber loss is proposed.Huber loss is in robust regress (robust regression. ) is used in the loss function, compared to the square error, the discrete value
R Language Generalized linear Model GLM () functionGLM (formula, family=family.generator, Data,control = List (...))Formula data relationships, such as y~x1+x2+x3Family: Each response distribution (exponential distribution family) allows various correlation functions to correlate the mean with the linear predictor.Common family:
Binomal (link= ' logit ')--the response variable is subject to two distributio
); theta = Theta-alpha (alpha_i) .*grad; end plot (0:49, Jtheta ( 1:50), char (Plotstyle (alpha_i)), ' LineWidth ', 2)% be sure to convert by Char function hold on if (1 = = Alpha (alpha_i))% The experiment found that Alpha was1 o'clock the effect is best, then the theta value after the iteration is the desired value theta_grad_descent = theta endendlegend (' 0.01 ', ' 0.03 ', ' 0.1 ', ' 0.3 ', ' 1 ', ' 1.3 '); Xlabel (' Number of iterations ') ylabel (' cost function ')% below is the pred
, 1)) A #Pre-valuation atPreY = w * x +b - - #loss value: The mean variance between the pre-estimate and the actual value -Loss = Tf.reduce_mean (Tf.square (PreY-y)) - #Optimizer: Gradient Descent method -Optimizer =Tf.train.GradientDescentOptimizer (learnrate) in #Training: Minimizing loss function -Trainer =optimizer.minimize (loss) to + With TF. Session () as Sess: - Sess.run (Tf.global_variables_initializer ()) the #print initial random coefficients * Print(
, meaning you have only 10 data, but there are 100 features, obviously, the data is not enough to cover all the features.You can delete some features (keep only data-related features) or use regularization.Exercises1.Don't know how to use both methods at the same time, are these two methods sequential related?Use dividing by the rangeRange = Max-min = 8836-4761 = 4075Vector/range after change to1.94381.27212.16831.1683For the above use mean normalizationAVG = 1.6382Range = 2.1683-1.1683 = 1X2 (4
I. Summary
Linear Regression Algorithms are a type of supervised learning algorithm used for Numerical Prediction of continuous functions.
After preliminary modeling, the process determines the model parameters through the training set to obtain the final prediction function. Then, the predicted value can be obtained by inputting the independent variable.Ii. Basic Process
1. Preliminary modeling. Determine
price of a house is whether the area is more important or the room orientation is more important.
We make x0 = 1, we can use vectors to represent
In the above formula, once Theta is determined, then our straight line is determined, and we are able to forecast the house price. So the job we're going to do is to determine theta.
The value of θ can have countless, how should we choose θ?
3. Model Establishment-least squares
O
Supervised Learning
Learn a function H: X → y
H is called a hypothesis.
1. Linear Regression
In this example, X is a two-dimensional vector, x1 represents living area, and x2 represents bedrooms.
Functions/hypotheses H
Set X0 = 1.
Now, given a training set, how do we pick, or learn, the parameters θ? Now it is used to evaluate the θ parameter.
One reasonable method seems to be to make h (x)
Mathematical model, if need to bank loans, according to the loan amount calculation, there are age, wages, assets and other factors, this translates into mathematics is:Now we are to fit a plane to make a diagram, but this fitting theoretical value and the results of the real difference, now we through the statistical error calculation method, we believe that each error is independent of the same distribution, and obey the mean value of 0 variance is the Gauss distribution of the square. Indepen
;Switch (in){Case 0:BreakCase 1://Creating a new Address BookCreateList (L);//inverse-order establishment of linear tablecout System ("pause");BreakCase 2: {//findGetelem (L);System ("pause");Break}Case 3://ModifyReviselist (L);System ("pause");cout BreakCase 4://AddListinsert (L);cout System ("pause");BreakCase 5:Printlist (L);Listdelete (L);cout System ("pause");break;//Output All informationCase 6:Printlist (L);System ("pause");BreakCase 7:cout Sys
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.