Linear Regression from Scratch: Statistical Approach

Let’s do this without optimizer. Just a bunch of statistical formulas.

A linear regression line.

Hello world! Welcome back to my post! Today I wanna share another project that I just done: a linear regression. But wait, this one is different! Usually I use either Scikit-Learn or Keras module to do machine learning stuff, but now, I decided to solve this regression problem using statistical approach. That’s essentially why we do not need optimization algorithm for this task — which makes this project relatively simple compared to other machine learning tasks.

Note: I share the full code used in this project at the end of this article.

Students exam score dataset

Before we jump into the code, I want you to know that the dataset used in this project is taken from here. The dataset itself is very small that it only contains 25 samples which we are going to divide into train/test set. Let’s first start to load the modules and these data.

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('student_scores.csv')
df.head()

As you can see the code above, I use Pandas to load the csv file and Matplotlib to display the regression line in our dataset. The computation itself is going to be done using Numpy. Anyway, after we run the code above, the following output should appear:

The first 5 data in our dataset.

Basically, the table beside tells us that we got 2 columns in our dataset, namely Hours (which tells how long a student spend their time for studying) and Scores (which stores the score they gained on an exam). Our objective here is to predict the exam score of a student based on their studying duration. Therefore, to make things look more straightforward, I wanna take the values of Hours column to be the x data while the Scores are going to be y data. I will also take the first 15 samples as the training set, while the rest are used for testing purpose.

Artificial Intelligence Jobs
x_train = df['Hours'].values[:15]
y_train = df['Scores'].values[:15]
x_test = df['Hours'].values[15:]
y_test = df['Scores'].values[15:]

Now as we have already defined the x and y, now that we are able to display it using a scatter plot. The blue circles and green dots in the figure below represent train and test data respectively.

plt.figure(figsize=(10,7))
plt.title('Train/test data distribution')
plt.scatter(x_train, y_train, c='b', s=36)
plt.scatter(x_test, y_test, c='g', s=14)
plt.xlabel('Hours of study')
plt.ylabel('Score')
plt.show()
All samples displayed in scatter plot.

Linear regression

The point of doing linear regression is to create a straight line which is able to approximate all data points with minimum error assuming that the independent variable (x) has a linear relationship to its dependent variable (y). The regression line itself can be defined using a simple linear function, in which our objective is to figure out the value of b_0 and b_1 in order to create the best-fit line to our samples.

Regression line function.

In fact, there’s already a formula to compute both b_0 and b_1 by calculating the existing data point coordinates. Here is the formula to compute those values:

Formula to calculate b_1.
Formula to calculate b_0.

In this case, x_bar represents the mean of all studying duration in hours while y_bar represents the average score of all students. Meanwhile, both x_i and y_i are used to denote the value of each sample. Below is the code implementation to the both formulas.

def coefficients(x, y):
x_mean, y_mean = np.mean(x), np.mean(y)

b1 = sum([(x_i-x_mean)*(y_i-y_mean) for x_i, y_i in zip(x,y)]) / sum([(x_i-x_mean)**2 for x_i in x])
b0 = y_mean - b1 * x_mean

return np.array([b0, b1])

We can see here that the coefficients() function takes 2 arguments, where both x and y are array of samples in our training set. The output of this function is an array with 2 elements which holds b_0 and b_1 respectively. Now it’s time to feed the function with our x_train and y_train data.

b0, b1 = coefficients(x_train, y_train)
print('b0 :', b0)
print('b1 :', b1)

If we run the code above, we should get the following output.

The values of b_0 and b_1 after being trained on our train dataset.

Now as the value of the two variables have been obtained, we can start drawing the regression line. The function of np.linspace() at the first line in the code below works by creating a list of 100 numbers ranging from 0 to 10 (inclusive). Next, each of the element in x_line is going to be processed with our b_0 and b_1, which is then stored in y_line list. This operation is essentially based on the formula to create a straight line, where b_0 is the intercept and b_1 is the slope. Finally, as both x_line and y_line have been defined, we can plot the regression line using plt.plot() function.

x_line = np.linspace(0, 10, 100)
y_line = b0 + b1*x_line
plt.figure(figsize=(10,7))
plt.scatter(x_train, y_train, c='b', s=36)
plt.plot(x_line, y_line, c='r')
plt.title('Regression line on train data')
plt.xlabel('Hours of study')
plt.ylabel('Score')
plt.show()
Regression line on train data.

Furthermore, we can also display the regression line on our test data. However it’s important to remember that the line is fitted using our previous training data — without taking into account the samples in our test set. So there’s a probability that the regression line below might not be the best-fit model to predict the test data.

plt.figure(figsize=(10,7))
plt.scatter(x_test, y_test, c='g', s=14)
plt.plot(x_line, y_line, c='r')
plt.title('Regression line on test data')
plt.xlabel('Hours of study')
plt.ylabel('Score')
plt.show()
The same regression line displayed on test data distribution.

Prediction

The core of linear regression model is the b_0 and b_1 values, which we just obtained in the previous part. Now we are going to predict both x_train and x_test using the predict() function which I defined below.

def predict(data, coef):
predictions = [coef[0] + coef[1]*x_i for x_i in data]
return predictions

The data argument above is just an array which contains all data that we are going to predict, whereas the next argument (coef) is also an array containing the value of b_0 and b_1. The output value of this function is an array of prediction values.

Now let’s first use the function to predict our train data.

The x values of our train data.
train_preds = predict(x_train, [b0, b1])
train_preds
Predictions on train data.

Next, we will do the exact same thing on test data.

X values of our test data.
test_preds = predict(x_test, [b0, b1])
test_preds
Predictions on test data.

In the next section we are going to find out the error values obtained from our prediction on train and test samples.

Error values

In classification tasks, we commonly use accuracy score to evaluate the performance of our model. However, we can not do that in regression problems since the labels are continuous numbers. What we can do in regression task is just to compute error value which denotes how close are our predictions towards the actual values. There are several formulas that we can choose to do that, such as MAE (Mean Absolute Error), MSE (Mean Square Error), RMSE (Root Mean Square Error), etc. In this case, I decided to use RMSE.

Root Mean Square Error formula.

The RMSE formula above is pretty straightforward to understand. If we turn that into a function, then the input argument is only 2: predicted and actual values, in which those are represented by yhat and y respectively. The index i in the formula indicates that the calculation is done iteratively on each predicted-actual pair. Lastly, the n variable here represents the number of samples that we compare. Below is the code implementation which works exactly the same as the RMSE formula above. Additionally, it’s important to keep in mind that the array size of actual and predicted have to be in the same length in order to work.

def rmse(actual, predicted):
return np.sqrt(sum([(pred_i-act_i)**2 for act_i, pred_i in zip(actual,predicted)])/len(actual))

Now let’s calculate the error values produced by the prediction of both train and test data. We can see the figure below that the value of the test error is slightly greater than train error. In fact, such thing is normal since we are fitting the regression line only with the train data.

Error on train and test data calculated using RMSE.

That’s all of this post. Feel free to comment if there’s a mistake in my explanation! See you!

Here’s the code:

References

3 Best metrics to evaluate Regression Model? by Songhao Wu. https://towardsdatascience.com/what-are-the-best-metrics-to-evaluate-your-regression-model-418ca481755b#:~:text=Overall%20Recommendation%2FConclusion,performance%20between%20different%20regression%20models.

How To Implement Simple Linear Regression From Scratch With Python by Jason Brownlee. https://machinelearningmastery.com/implement-simple-linear-regression-scratch-python/

Linear Regression in Python with Scikit-Learn by Scott Robinson. https://stackabuse.com/linear-regression-in-python-with-scikit-learn/

Don’t forget to give us your ? !


Linear Regression from Scratch: Statistical Approach was originally published in Becoming Human: Artificial Intelligence Magazine on Medium, where people are continuing the conversation by highlighting and responding to this story.

Via https://becominghuman.ai/linear-regression-from-scratch-statistical-approach-9532c11cacc2?source=rss—-5e5bef33608a—4

source https://365datascience.weebly.com/the-best-data-science-blog-2020/linear-regression-from-scratch-statistical-approach

How to Approach Ethical AI Implementation?

A practical guide to implementing ethical Artificial Intelligence (AI) — This article was present during the AIBotics 2020

Via https://becominghuman.ai/how-to-approach-ethical-ai-implementation-c2813bd344ac?source=rss—-5e5bef33608a—4

source https://365datascience.weebly.com/the-best-data-science-blog-2020/how-to-approach-ethical-ai-implementation

Im a Data Scientist Not Just The Tiny Hands that Crunch your Data

Not everyone “gets” the role of the Data Scientist — including management. While there can be frustrating aspects of being a data scientist, there are effective ways to go about fixing them.

Originally from KDnuggets https://ift.tt/3iRlGf5

source https://365datascience.weebly.com/the-best-data-science-blog-2020/im-a-data-scientist-not-just-the-tiny-hands-that-crunch-your-data

Top Stories Sep 14-20: Automating Every Aspect of Your Python Project; Deep Learnings Most Important Ideas

Also: Statistics with Julia: The Free eBook; Online Certificates/Courses in AI, Data Science, Machine Learning from Top Universities; Autograd: The Best Machine Learning Library You’re Not Using?; Implementing a Deep Learning Library from Scratch in Python

Originally from KDnuggets https://ift.tt/3kAtulJ

source https://365datascience.weebly.com/the-best-data-science-blog-2020/top-stories-sep-14-20-automating-every-aspect-of-your-python-project-deep-learnings-most-important-ideas

DataSciencePR Network has officially reached a strategic partnership with Evedo

source https://365datascience.weebly.com/the-best-data-science-blog-2020/datasciencepr-network-has-officially-reached-a-strategic-partnership-with-evedo

What an Argentine Writer and a Hungarian Mathematician Can Teach Us About Machine Learning Overfitting

This article presents some beautiful ideas about intelligence and how they related to modern machine learning.

Originally from KDnuggets https://ift.tt/32MNH1y

source https://365datascience.weebly.com/the-best-data-science-blog-2020/what-an-argentine-writer-and-a-hungarian-mathematician-can-teach-us-about-machine-learning-overfitting

7 steps of RPA implementation for enterprise digital transformation

RPA implementation for enterprise digital transformation

In the last three to four years, robotic process automation has become an integral part of enterprise digital transformation. The effects of RPA in digital transformation are such that the technology generated around $1 billion in revenue in the year 2019.

In a survey by Deloitte, 53% of respondents said that RPA implementation has already begun in their enterprise.

On the other hand, Gartner predicts that within the next two years, 72% of the organizations will be working with robotic process automation solutions.

The above statistics show a positive trend in RPA adoption. They also show that an increasing number of enterprises are focusing on digital transformation through RPA.

RPA Implementation Solutions: Saving you from Productivity Loss

Your enterprise is not untouched by productivity loss. It mainly occurs due to:

  • Inefficient processes
  • Poor tracking
  • Communication gaps
  • Ineffective collaboration
  • Poor management

What you want to achieve is:

  • Efficiency like the Japanese MNCs
  • 50% increase in productivity
  • 99% better accuracy in your operations
  • Improved decision-making from employees
  • Innovative action steps for overall organizational improvement
  • A digital empowered enterprise the 21st century

But the problems occur when you realize that all of these don’t happen because of the activities that your employees do every day — these activities are nothing but bottlenecks in their productivity.

The role of RPA in digital transformation is that it transforms these bottlenecks in productivity into opportunities for maximizing it.

RPA supports digital transformation by taking off the unproductive, inefficient tasks from your team. You can delegate operations that no longer contribute to the growth of your employees.

Big Data Jobs

When you embark on digital transformation using RPA, you are essentially saying to the employees that you value their time and would rather use it for more productive and creative activities.

If your employees feel that their time is being used wisely, they will start using it wisely.

On the other hand, once your employees are onboard the productivity train, your organization will automatically become a high-output entity.

The gap between where you are and where you want to reach will be effectively minimized once RPA and digital transformation start working together.

RPA Services: Building your Virtual Workforce

RPA implementation is much more than a cost-cutting machine for your enterprise. It is a virtual workforce that complements your human resources.

Your enterprise is more in need of Robotic Process Automation solutions than you can imagine.

Some of the workforce challenges you might be facing include:

  • Unavailability of employees after office hours.
  • Limited accessibility to human competencies.
  • Human errors due to exhaustion, tiredness, burnout.
  • Fixed and high-compensations even without projects.
  • Managing employees and their complaints

When RPA and digital transformation work together, you can build a virtual workforce that solves all your workforce challenges.

The virtual workforce of bots relieves your employees of tedious tasks. In essence, you’ll have two separate workforces in your enterprise — RPA virtual workers and your human resources.

Embarking on digital transformation using RPA allows you to delegate the mundane tasks to your virtual workers and the creative, decision-making tasks to your human resources.

Trending AI Articles:

1. Microsoft Azure Machine Learning x Udacity — Lesson 4 Notes

2. Fundamentals of AI, ML and Deep Learning for Product Managers

3. Roadmap to Data Science

4. Work on Artificial Intelligence Projects

How Digital Transformation through RPA Delivers Business Value?

The primary question is this — How can RPA help with digital transformation in terms of value delivered to your business?

Robotic Process Automation solutions have a lot of use cases in the entire enterprise. From accounting to troubleshooting, the role of RPA in digital transformation of your enterprise is beyond imagination.

Here’s how RPA and digital transformation work together to deliver business value:

1. Overall organizational value

The first thing RPA will do is align your business goals with perfect resource management and deliver overall organizational value. How so?

Improved enterprise performance

  • Your enterprise is a connected network of systems like all enterprises. If one process improves, all others get better automatically.
  • RPA implementation doesn’t stop at one process or in one department.
  • RPA supports digital transformation at the managerial level as well as the bottom-line level.
  • Wherever Robotic Process Automation is a possibility, it should happen to improve the overall business performance.

Reduction in costs

  • One of the most significant benefits of Robotic Process Automation is a reduction in costs. RPA implementation brings about 25% to 60% cost savings in your operations.
  • The main costs associated with employees include monthly fixed salaries, bonuses, perks, pension plans, provident funds, employee engagement, and whatnot.
  • When you step on to digital transformation using RPA, you don’t have to spend money on any of the above.
  • RPA will allow you to replace workers in jobs which can be automated with a one-time investment.

Better opportunities

  • Now that you will use RPA consultants services for digital transformation, you will be left with employees who used to do the work earlier.
  • In essence, you now have the opportunity to train this workforce at a lower cost in different skills.
  • You are opening doors to your employees for learning the best possible human skill.
  • In fact, you can train your employees in managing and supervision of RPA technologies to keep them relevant in the industry.

2. Value to customers

Most enterprises, including yours, will use RPA in digital transformation to achieve the ultimate result — maximizing customer satisfaction. Well, Robotic Process Automation provides unmatched value in uplifting the user experience.

Faster data entry

  • Banks and healthcare institutions are already taking advantage of RPA implementation services to perform faster data entry.
  • Manual form filling is a tedious task, and the customer has to wait for a long time as the person sitting on the other side of the desk can only work at a limited speed.
  • Robotic Process Automation solutions increase data entry speed by 50%. On the other hand, it will reduce the errors in data entry tenfold.
  • RPA software bots are instructed to fill in information based on specific rules. There is almost no chance of robots making errors in information filling.
  • When you increase the speed of processes like filling forms, quickly accessing customer data, and producing error-free consumer results, your customer experience skyrockets.
  • They understand that your focus is on serving them in a much better way than making them wait in line.

Streamline customer service workflow

  • RPA implementation, combined with Artificial Intelligence(AI), can streamline customer service workflows to provide maximum value to each customer.
  • It can provide immediate responses to customers based on some predefined parameters and direct the customers to the right department.
  • On the other hand, RPA software bots allow customer service reps to easily access information and in real-time.
  • RPA and digital transformation enable the software to trigger responses and provide the right information at the right time, highly improving customer service delivery.

3. Value to Human Resources

Now that you have understood the overall organization value of RPA and the value to customers, it is imperative to understand how RPA consulting & implementation services will impact employee engagement.

Increase in employee satisfaction

  • One of the primary benefits of Robotic Process Automation is an increase in employee satisfaction.
  • When your staff is relieved from mundane and boring tasks like copying and pasting data, they will feel that they are valued more in the organization.
  • Enterprise digital transformation using RPA will allow employees to focus on more productive and creative tasks. Once employees feel that their time is being valued, they will start using it wisely.
  • On the other hand, when democratic automation takes place, employees become motivated to automate their own processes.
  • With no-code automation, your team can seamlessly automate processes that have low-value in terms of operability.
  • Once they are ready to handle more challenges, their job satisfaction will increase twofold.

Source better candidates

  • This is a direct benefit of Robotic Process Automation solutions. When you implement RPA in your human resource department, you can reap significant advantages. One of them is sourcing better candidates.
  • Your HR department is probably overburdened with resumes lying on their desk and hard drive. Robotic Process Automation can scan through millions of resumes and select the best candidates that match your parameters.
  • It will reduce the time of your HR department in searching for candidates. It also allows HR managers to improve employee engagement through quick access to employee data.

Productivity boost

  • RPA supports digital transformation by giving your enterprise a productivity boost. How so?
  • RPA consulting services will increase your output delivery speed as most of the manual and mundane processes will be automated.
  • While your employees can churn out 5 units of output, RPA implementation can churn out nearly 10–15 units in the same time.
  • RPA services allow your employees to take up productive tasks where their skills make more sense. They can plan and manage the operations instead of filling out the formalities when they are not executing.
  • On the other hand, your enterprise will achieve better results in less amount of time. You can plan an automation strategy that combines human efforts and machines to deliver maximum productivity boost.

Enterprise Digital Transformation using RPA: 7 step Journey

Now that you understand the role of RPA in digital transformation for your enterprise, you probably want to get started as soon as possible.

You can cut down your operational costs, increase your productivity, and multiply your profitability — all the while providing a world-class customer experience.

RPA implementation services, thus, provide you with a win-win situation. Whichever industry your business is in, implementing RPA services have a plethora of use cases for you.

Read this blog and learn the 33 different use cases of Robotic Process Automation in 11 major industries.

Once you understand how RPA can benefit your business, you should get started with your RPA journey as soon as possible.

7 steps to Digital Transformation with RPA

There’s a lot of information out there about effectively implementing RPA. It can confuse you and take you a step back.

Don’t worry — we have compiled a 7-step journey of all the necessary things you need for implementing Robotic Process Automation solutions in your organization. Keep reading and transform your organization today.

1. Know more about RPA

  • While most experts would say that you start your automation journey by setting up an objective, we believe that you should start by learning as much as you can about the technology.
  • Robotic Process Automation is a big deal when it comes to digital transformation. You don’t want to automate the wrong processes. You must learn about the tools and technologies of RPA.
  • This step is essential because it prepares you to bring an enterprise-wide change of digital transformation using RPA. The more knowledge you have, the better you can educate the people working on your team.
  • It is crucial to research the long-term effects of RPA, scalability of the technology, sustainability, and the overall value it will deliver to your organization.
  • If you have a complete understanding of RPA implementation, you can identify the need for Robotic Process Automation solutions for different processes in your organization.

2. Define your RPA objectives

  • The next step is to determine the RPA objectives. It is a critical step — one that can make or break your digital transformation strategy.
  • You must identify the long-term objectives like increase in productivity, employee substitution, reduction in costs, and many more. These objectives will provide long-term value with automation.
  • On the other hand, you must also determine any short-term objectives you want to achieve with RPA and digital transformation. These include completing one-time data entry tasks, triggering responses for logging in, sourcing a list of information, etc.
  • All the RPA objectives must focus on achieving your overall organizational goal. RPA isn’t a fancy technology to become a machine.
  • For proper implementation of RPA solutions, you need to identify the key areas under the objectives where RPA is required.

3. Deploy RPA on a small scale

  • While most companies want quick results, RPA services are not your usual “get-productive-quick” scheme.
  • Even though it increases your productivity, start small. Since it is a new technology, you might not want to risk every process of your enterprise.
  • It is better to automate micro-processes that occur every day rather than processes that happen only once or twice a month. In the beginning, your focus should be to automate the small tasks with specific actions that can be completed quickly.
  • Often single processes are much better and easier to automate at the beginning than long, complex processes.
  • In essence, it is like taking a test run of digital transformation using RPA. It allows you to see how RPA implementation is working for you and whether it is the right direction for you or not.

4. Scale your RPA efforts

  • Once you are satisfied that your RPA efforts are in the right direction through small scale testing, you are ready to implement it on a larger level.
  • It starts by identifying the right candidates for business process automation. The driving question shouldn’t be “ Can we automate this process?” but rather “ Should we automate this process?”
  • When you scale your RPA implementation, it is better to take help of RPA consulting services and get the right advice in compliance, scalability, and optimization.
  • You must find the processes that have a lot of bottlenecks and deliver the least value to your business. If you think that a process can be completed without human intervention, it is a good candidate for process automation.
  • Gradual scaling will help you identify more opportunities for digital transformation through RPA. You can optimize processes without compromising or disrupting your workflow.

5. Implement governance and compliance

  • Now if you are planning to use RPA as your long-term strategy for digital transformation, you need to have governance in place. You must ensure that process automation is in alignment with your business goals.
  • On the other hand, you must make sure that RPA compliance doesn’t take the backseat. Unethical usage and biases in RPA processes can harm your business in the long-run.
  • You should provide proper training to your employees for working in accordance with RPA and digital transformation. The IT team will be of great help in equipping your team with the necessary skills.
  • Executives or managers from the project management team must oversee RPA implementation at different stages in the organization.
  • The main purpose of governance is to ensure that the right processes are being automated and there’s no gap between the results you expect to achieve from RPA and what you actually achieve.

[Read Also: Salesforce RPA Integration: A Comprehensive Guide]

6. Build a virtual workforce

  • The penultimate step is to scale your RPA efforts in a way such that you are able to build a digital workforce of bots, available at your service 24×7.
  • As you gradually scale up RPA implementation by identifying processes to automate one after the other, enterprise digital transformation becomes easier.
  • In no time, you will have an army of bots working at your disposal, completing all the tasks that your employees don’t want to do.
  • In the meantime, you also need to optimize your existing bots involved in business process automation. RPA software like UiPath, Automation Anywhere, BluePrism, etc., allow you to build your digital workforce without much effort.
  • Building a digital workforce will bring an enterprise-wide wave of digital transformation. Your employees will be better equipped to deal with RPA once your organization is on board the digital workforce.

7. Measure and improve

  • The last step in digital transformation through RPA is measuring the performance of your digital workforce and improving the implementation.
  • You must regularly record the successes and failures of your RPA-optimized processes to measure how they are performing.
  • It involves setting a list of key KPIs that you wish to achieve and overseeing whether RPA implementation is providing you the expected results or not.
  • As you go along the way, you will find discrepancies, which will allow you to make improvements and adjust your RPA services accordingly.
  • Measuring the performance is directly related to the RPA objectives that you want to achieve. You primarily want to increase efficiency, reduce costs, and multiply your productivity.
  • Set up regular tracking to ensure that you are conducting a thorough analysis of your processes and are getting a real-image of the situation to improve it further.

[Keep Reading: RPA or AI — What will Benefit Your Organization the most]

RPA Services are the future of Digital Transformation

RPA and AI are the primary technologies for digital transformation. However, you cannot begin your journey with one and ditch the other.

Robotic Process Automation solutions enable you to reap the benefits of automating complex business processes. It allows you to focus on what’s more important.

RPA implementation is not elimination but the substitution of your valuable employees with bots that can deliver better value in the same amount of time.

However, the steps to digital transformation using RPA are not absolute. These are a common framework that can help you to take advantage of RPA effectiveness.

If you need to talk to an RPA expert for more information, give us a call. BoTree Technologies has the perfect mix of RPA developers to fulfil all your automation needs.

Don’t forget to give us your ? !


7 steps of RPA implementation for enterprise digital transformation was originally published in Becoming Human: Artificial Intelligence Magazine on Medium, where people are continuing the conversation by highlighting and responding to this story.

Via https://becominghuman.ai/7-steps-of-rpa-implementation-for-enterprise-digital-transformation-64da673a9a6e?source=rss—-5e5bef33608a—4

source https://365datascience.weebly.com/the-best-data-science-blog-2020/7-steps-of-rpa-implementation-for-enterprise-digital-transformation

We are all already addicted to AI

source https://365datascience.weebly.com/the-best-data-science-blog-2020/we-are-all-already-addicted-to-ai

Deep Generation of Face Images from Sketches

The generation of facial images has important applications in various industries, such as criminal investigations, character design…

Via https://becominghuman.ai/deep-generation-of-face-images-from-sketches-6f28d7ef0522?source=rss—-5e5bef33608a—4

source https://365datascience.weebly.com/the-best-data-science-blog-2020/deep-generation-of-face-images-from-sketches

Design a site like this with WordPress.com
Get started