Category: Thuật toán

  • Linear regression machine learning with Excel

    Linear regression machine learning with Excel

    Linear regression machine learning with Excel

    Linear regression is a simple machine learning algorithm that has many uses for analyzing data and predicting outcomes. Linear regression is especially useful when your data is neatly arranged in tabular format. Excel has several features that enable you to create regression models from tabular data in your spreadsheets.

    1. What is a linear regression?

    As the name implies, linear regression is an approach to modeling the relationship between a dependent variable $y$ and one or more independent variables denoted as $x$ in a linear form. Linear means that the dependent variable is directly proportional to the independent variables. Keeping other things constant if $x$ is increased/decreased then $y$ also changes linearly. Mathematically the relationship is expressed in the simplest form as: $$y=Ax+B$$

    Here $A$ and $B$ are constant factors. The goal in supervised learning using linear regression is finding the value of constants  $A$ and $B$ using the data sets. Then we can use it to predict the values of $y$ in the future for any values of  $x$. Now, the cases where we have a single independent variable is called simple linear regression, while if there is more than one independent variable, then the process is called multiple linear regression.

    Quick facts about Linear Regression

    It’s a basic and commonly used type of predictive analysis. Three major uses for regression analysis are:
    1. Determining the strength of predictors
    2. Forecasting an effect
    3. Trend Forecasting

    There are several types of linear regression analyses available to researchers.

    • Simple linear regression
    • Multiple linear regression
    • Logistic regression
    • Ordinal regression
    • Multinominal regression
    • Discriminant analysis

    2. Application of Linear Regression

    Linear regression was the first type of regression analysis to be studied rigorously, and to be used extensively in practical applications. This is because models which depend linearly on their unknown parameters are easier to fit than models which are non-linearly related to their parameters and because the statistical properties of the resulting estimators are easier to determine. Linear regression can be applied to many situations. Most of the applications fall into one of the following two broad categories:

    • Prediction: In prediction or forecasting, linear regression can be first used to fit a predictive model to an observed data set of $y$ and $x$ values. After developing such a model, the fitted model can be used to make a prediction of the value of $y$ for an additional value of $x$.
      For example: If we have a dataset of rainfall amounts and corresponding temperatures, then we can fit a linear model and use it to predict the amount of rainfall for a temperature value whose rainfall amount is not known beforehand.
    • Finding strength of relationship: Given a variable $y$ and a number of independent variables $x_1, …, x_p$ that may be related to $y$, linear regression analysis can be used to quantify the strength of the relationship between $y$ and the $x_j$, to assess which $x_j$ may have no relationship with $y$ at all, and to identify which subsets of the $x_j$ contain redundant information about $y$.
      For example: If we have a dataset of rainfall amounts and corresponding humidity and temperatures, then we can use regression analysis to find out how strongly does the amount of rainfall depends upon each of these factors.

    To estimate the parameters of the linear regression model various techniques can be used. The most common ones are Least Squares (LS) method and maximum-likelihood estimation methods. Let’s discuss here an example of simple linear regression using ordinary least squares method.

    Least squares estimation:

    How do we go about picking or finding the parameters of the model? One way is to make the predicted value of $y$ as close to the actual value of the training set. For example: Suppose we have a training data $(x_{data}, y_{data})$. Then the reasonable thing to do would be to make the predicted value $y$ as close to $y_data$ as possible. Therefore we try to minimize the sum of the square of the error i.e $$S = S_j (y_{{data}_j} – y_­­­­j)^2$$

    For the simple case of a single independent variable after solving we obtain the following formulas for $A_0$ and $A_1$. $$A_{0}=\frac{n \sum_{i=1}^{n} y_{i} * x_{i}-\sum_{i=1}^{n} y_{i} * \sum_{i=1}^{n} x_{i}}{\sum_{i=1}^{n}\left(x_{i}-\text {mean}\right)^{2}}$$

    $$A_{1}=y-A_{0} * \text {mean}
    $$

    3. Linear regression machine learning with Excel

    https://www.youtube.com/watch?v=p4YgDMRV8aI&feature=youtu.be

    Let’s look at an example: The data in the table below shows the temperature during the race and the corresponding average finish time in minutes of a marathon.

    Linear regression machine learning with Excel 1

    From the scatter plot we can see that the relationship between the $x$ & $y$ is somewhat linear. Using the formula we get the values of the parameters, $A_0 = 0.688 , A_1= 191.83$.

    How do we make Prediction?

    Prediction for a new test value of x is done simply by putting the value in the equation for the linear regression model. We now have the parameters of the simple linear regression model: $$y = 0.688x + 191.83$$

    We can use it to predict the average completion time for different temperatures. For example, when the temperature is 71 F our model predicts the average completion time to be, $$y = 0.688*71 + 191.83 = 240.68 minutes.$$

    Linear Regression Chart

    Linear regression machine learning using data visualization feature in Excel

    One of the most intuitive is the data chart tool, which is a powerful data visualization feature. For instance, the scatter plot chart displays the values of your data on a cartesian plane. But in addition to showing the distribution of your data, Excel’s chart tool can create a machine learning model that can predict the changes in the values of your data. The feature, called Trendline, creates a regression model from your data. You can set the trendline to one of several regression algorithms, including linear, polynomial, logarithmic, and exponential. You can also configure the chart to display the parameters of your machine learning model, which you can use to predict the outcome of new observations.

    You can add several trendlines to the same chart. This makes it easy to quickly test and compare the performance of different machine learning models on your data.

    excel data science trendline

    Above: Excel’s Trendline feature can create regression models from your data.

    In addition to exploring the chart tool, Learn Data Mining Through Excel takes you through several other procedures that can help develop more advanced regression models. These include formulas such as LINEST and LINREG, which calculate the parameters of your machine learning models based on your training data.

    While this might not be the most efficient way to do production-level data science work, it is certainly a very good way to learn the workings of machine learning algorithms.

    https://www.newtechdojo.com/learn-linear-regression-using-excel/

    https://venturebeat.com/2020/12/30/you-dont-code-do-machine-learning-straight-from-microsoft-excel/

  • Đề thi BEBRAS 2020 lớp 3 4 và đáp án

    Đề thi BEBRAS 2020 lớp 3 4 và đáp án

    Đề thi BEBRAS 2020 lớp 3 4

    Hướng dẫn giải đề thi Bebras 2020 lớp 3 – 4

    Phần A. Với mỗi câu trả lời đúng, thí sinh được 6 điểm

    Câu 1. Trong mạng xã hội TeeniGram, mỗi người tham gia có thể theo dõi những người tham gia khác. Nếu trong một nhóm người tham gia TeeniGram có một người được tất cả những người còn lại theo dõi và người này không theo dõi bất cứ ai trong nhóm thì người này được gọi là “Thần tượng”. Biết rằng trong nhóm 5 bạn hải ly Alan, Don, Frances, Grace và Robin:

    • Alan theo dõi Don và Grace.
    • Don theo dõi Grace và Robin.
    • Fraces theo dõi Alan, Grace và Robin.
    • Robin theo dõi Alan và Grace.

    Hỏi ai là thần tượng trong nhóm bạn?
    A) Alan

    B) Don

    C) Grace

    D) Robin

    Câu 2. Hải ly chạy thể dục buổi sáng. Bạn ấy dự định đi tới các vị trí 1, 2, 3 và 4 (không nhất thiết theo thứ tự) theo các đường kẻ trong công viên như hình dưới đây.

    De thi Bebras nam 2020 lop 3 4 cau 2
    Mỗi hình vuông đơn vị có cạnh 100 mét.

    Trong công viên có một số vũng lầy màu xám mà bạn ấy không thể đi qua. Hỏi quãng đường ngắn nhất để hải ly đi tới tất cả các vị trí 1, 2, 3 và 4 là bao nhiêu mét?

    A) 1200

    B) 1000

    C) 800

    D) 600

    Câu 3. Hải ly phải đóng gói 5 quả bóng lớn, 2 quả bóng trung bình và 5 quả bóng nhỏ vào hộp. Bạn ấy có 3 hộp lớn, 5 hộp trung bình và 3 hộp nhỏ. Một quả bóng có thể được đặt vừa vào chiếc hộp tương ứng hoặc lớn hơn. Đồng thời mỗi hộp chỉ có thể chứa đúng một quả bóng.

    De thi Bebras nam 2020 lop 3 4 cau 3
    Hỏi hải ly có thể đóng gói được tối đa bao nhiêu quả bóng?
    A) 8

    B) 9

    C) 10

    D) 11

    Câu 4. Ba nhóm người tuyết, mỗi nhóm có 5 người đứng thành hàng. Mỗi bạn lần lượt từ trái sang phải lấy một chiếc mũ theo thứ tự từ trên xuống dưới.

    De thi Bebras nam 2020 lop 3 4 cau 4

    Hỏi các nhóm người tuyết phải lấy các chiếc mũ trong các nhóm nào để mỗi bạn lấy được chiếc mũ theo đúng kích thước của mình?

    Câu 5. Hải ly có cách vẽ tranh bằng cách cạo đi lớp màu xám bên trên của tờ giấy màu như hình dưới đây:

    bebras 2020 lop 3 4 cau 5
    Hỏi trong các bức tranh dưới đây, bức tranh nào xuất hiện đúng ba màu của lớp màu bên dưới?

    bebras 2020 lop 3 4 cau 5 2.jpg

    Phần B. Với mỗi câu trả lời đúng, thí sinh được 9 điểm.

    Câu 6. Hải ly Rebecca có một số khối lập phương kích thước khác nhau như hình dưới đây. Các số biểu diễn cho kích thước của các khối lập phương.

    bebras 2020 lop 3 4 cau 6.jpg

    Bạn ấy muốn sắp xếp các khối lập phương từ trái sang phải theo thứ tự từ bé tới lớn bằng cách lần lượt đổi chỗ các khối lập phương cạnh nhau. Hỏi bạn ấy cần đổi chỗ các khối lập phương ít nhất bao nhiêu lần?
    A) 9

    B) 8

    C) 7

    D) 6

    Câu 7. Đầu bếp hải ly có một chiếc két sắt để cất giữ những công thức bí mật. Chiếc két sắt được khóa bằng chiếc khóa dưới đây.

    bebras 2020 lop 3 4 cau 7

    Để mở được chiếc két sắt, hải ly phải lần lượt xoay mũi tên sang bên trái, sang bên phải để mũi tên chỉ vào các chữ cái có trong mật mã mở khóa. Ví dụ để xoay được chữ cái B và chữ cái H thì hải ly lần lượt xoay Đề thi BEBRAS 2020 lớp 3 4 và đáp án 2 như hình dưới đây.

    bebras 2020 lop 3 4 cau 72

    Hỏi hải ly phải quay khóa như thế nào để mở két sắt nếu mật khẩu là CHEFDG?

    bebras 2020 lop 3 4 cau 73

    Câu 8. Ở thành phố hải ly, các bạn hải ly thường sử dụng xe buýt để di chuyển. Dưới đây là một số chuyến xe buýt và lịch trình di chuyển.

    bebras 2020 lop 3 4 cau 8
    Hải ly xuất phát tại trạm A lúc 11:05 và muốn tới trạm D. Hỏi bạn ấy có thể tới trạm D sớm nhất vào lúc mấy giờ?

    A) 12:00

    B) 11:20

    C) 13:00

    D) 12:20

    Câu 9. Hải ly Diana nhận nhiệm vụ trang trí 5 bàn tiệc cho ngày lễ sắp tới. Bạn ấy được sử dụng:

    • Hai loại thảm trải bàn;
    • Ba loại hoa.

    Các bàn được trang trí phải thỏa mãn điều kiện:

    • Dùng tất cả các loại hoa hoặc chỉ dùng đúng một loại hoa.
    • Hai bàn cạnh nhau không được trải cùng loại thảm trải bàn.

    Hỏi trong các cách trải bàn dưới đây, cách nào thỏa mãn điều kiện đã cho?