Tag: excel

  • 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/

  • Hướng dẫn chuyển dòng thành cột trong Excel

    Hướng dẫn chuyển dòng thành cột trong Excel

    Hướng dẫn cách chuyển dòng thành cột trong Excel

    Cách chuyển dòng thành cột (chuyển đổi, hoán vị dòng thành cột, chuyển hàng thành cột) trong Excel bằng tính năng Paste Transpose hoặc sử dụng hàm TRANSPOSE().

    Xem thêm Sửa lỗi font tiếng Việt file CSV Google Microsoft Forms

    1. Các bước chuyển dòng thành cột trong Excel

    Để chuyển đổi hàng (row) thành cột (col – column) ta sử dụng tính năng Paste Transpose, cụ thể như sau:

    1️⃣ Mở file Excel có nhu cầu chuyển đổi cột thành hàng hoặc ngược lại.

    2️⃣ Bôi đen (chọn) những hàng muốn chuyển đổi sang cột, hoặc ngược lại. Nhấn chuột phải và chọn Copy hoặc sử dụng tổ hợp phím Ctrl + C.

    3️⃣ Di chuyển con trỏ chuột (dấu nhắc) đến vị trí muốn tạo bảng mới. Lúc này có 2 trường hợp:

    • Đối với Excel 2019, 2016 và 2013: Nhấn chuột phải và chọn Paste Transpose ở hàng Paste Options như trong hình vẽ sau.

    Hướng dẫn cách chuyển dòng thành cột, chuyển đổi hàng sang cột Paste Transpose trong Excel

    • Đối với Office cũ (như Excel 2003) thì bấm chuột phải và chọn Paste Special. Lúc này, hộp thoại Paste Special xuất hiện. Bạn tích chọn vào ô Transpose. Cuối cùng, nhấn OK để hoàn thành.

    chuyen dong thanh cot trong excel 2003

    2. Hướng dẫn chi tiết cách chuyển dòng thành cột trong Excel

    https://youtu.be/6tJkmf27L1o

    3. Chuyển dòng thành cột bằng hàm TRANSPOSE()

    1. Đếm các hàng và cột của bảng (vùng dữ liệu) mà bạn muốn chuyển đổi. Giả sử bảng của chúng ta là 6 cột9 hàng.
    2. Sử dụng chuột để chọn (bôi đen) một các ô trống trong sheet Excel của bạn có kích thước đúng bằng kích thước của bảng sau khi chuyển đổi. Vì hàm TRANSPOSE chuyển hướng dọc và ngang (chuyển hàng thành cột và cột thành hàng) của một bảng đã chọn nên bạn cần phải chọn một vùng trống vừa đủ cho số hàng và cột của bạn. Trong ví dụ ở trên, bảng của chúng ta có 6 cột9 hàng nên khoảng trống phải có đủ chỗ cho 9 cột6 hàng.
    3. Nhấn F2 (hoặc bấm chuột vào ô nhập công thức f(x)) để vào chế độ chỉnh sửa.
    4. Nhập hàm TRANSPOSE và nhập dải dữ liệu mà bạn muốn chuyển đổi vào trong cặp ngoặc đơn.
      Ví dụ, bảng của chúng ta bắt đầu từ ô A1 và kết thúc ở ô F9 (hình vẽ) thì nhập =TRANSPOSE(A1:F9).

    chuyen dong thanh cot trong excel bang ham transpose

    1. Nhấn Ctrl + Shift + Enter .

    Lưu ý: Bạn cần nhấn Ctrl + Shift + Enter vì đây là một công thức mảng, nhấn Enter  nó sẽ không hoạt động.

    Lúc này, bảng của chúng ta đã xuất hiện và cách dòng đã chuyển thành cột, các cột đã chuyển thành dòng như trong hình dưới đây.

    chuyen dong thanh cot trong excel bang ham transpose khong giu dinh dang

     

    Ưu điểm của hàm TRANSPOSE:

    • Bảng mới tạo thành giữ lại kết nối với bảng nguồn và bất cứ dữ liệu nguồn nào bị thay đổi thì bảng mới cũng tự động thay đổi theo.

    Nhược điểm của hàm TRANSPOSE:

    • Định dạng bảng ban đầu không được lưu trong bảng chuyển đổi.
    • Nếu có bất kỳ ô trống nào trong bảng nguồn, các ô tương ứng trong bảng chuyển đổi sẽ chứa giá trị 0 mặc định, không thể sửa được.
    • Không thể chỉnh sửa bất kỳ ô nào trong bảng chuyển đổi, vì mỗi ô là một phần tử của mảng, bạn chỉ có thể thay đổi toàn bộ bảng chuyển đổi bằng cách gõ lại công thức của cả mảng hoặc sửa các ô ở bảng ban đầu.
  • Sửa lỗi font tiếng Việt file CSV Google Microsoft Forms

    Sửa lỗi font tiếng Việt file CSV Google Microsoft Forms

    Sửa lỗi font tiếng Việt file CSV Google Microsoft Forms

    Khi thầy cô sử dụng Microsoft Forms hoặc Google Forms, các dữ liệu phản hồi biểu mẫu (các câu trả lời bài làm của học sinh, các câu trả lời khảo sát…) được lưu dưới dạng file .csv

    1. Nguyên nhân lỗi font tiếng Việt của file CSV

    Các file CSV này thưởng bị lỗi font tiếng Việt khi mở bằng phần mềm MS Excel. Nguyên nhân là do Excel mặc định chọn bảng mã cho tệp csv này là encoding của châu Âu, còn file CSV chúng ta được lưu ở bảng mã UTF-8.

    2. Cách sửa lỗi font file csv bằng Excel

    Chúng ta không mở trực tiếp tệp vừa tài về, mà thực hiện như sau:

    Bước 1. Tạo 1 file Excel mới

    Bước 2. Chọn thẻ Data rồi chọn tiếp Import from Text/CSV (Chỗ tô màu vàng trong hình vẽ sau)

    Cách sửa lỗi font tiếng Việt file CSV

    Bước 3. Chọn file csv bị lỗi font mà các thầy cô đã tải về. Ô File Origin chọn là 65001: Unicode (UTF-8) như hình vẽ sau.

    Hướng dẫn cách sửa lỗi font tiếng Việt file CSV khi mở trong Excel

    Bước 4. Ấn chọn Load và chờ Excel nạp file này. Sau đó, thầy cô lưu lại file Excel mới này và sử dụng bình thường.

    Hướng dẫn chi tiết cách sửa lỗi font file csv, cách chỉnh lỗi font file CSV mời thầy cô xem trong video sau đây:

    Xem thêm: