✍️Introduction
- scikit-learn is one of the most famous python libraries for machine learning.
- scikit-learn allows you to easily build and train machine learning models through its simple and well designed API.
- However, I will try to simplify the API for beginners.
1⃣ Estimators
- The process of learning parameters from input data is called "Estimation", and therefore any object that learns some parameters from data is called an "Estimator".
- The estimation process itself is performed by calling the fit( ) method of any estimator object.
Example 1: (fill missing values in an array)
Step 1
We have an array of numbers of shape (15,1) with sum null values.
Step 2
We use scikit-learn's simple imputer to impute (or replace) missing values with the mean of the array (strategy = 'mean')
👇👇
Step 3
We estimate the mean of the array using the fit( ) method of the imputer object.
(As previously explained, fit( ) method is used to estimate a parameter, the mean in this case, from input data)
Step 4
We can access the learned parameter using the statistics_ attribute.
Notice that up until this point, we haven't actually replaced the missing values.
All we've done is calculate the mean of the array.
The next logical step is to use the learned parameter (the mean) to replace the missing values.
That's when transformers kick in.
2⃣ Transformer
- A transformer is an estimator that can use the learned parameters to transform the data.
- The transformation process is performed using the transform( ) method.
e.g., The simple imputer object in the previous example can use the learned parameter (the mean of the array) to replace the missing values in the array.
Example 1: (fill missing values in an array)
Step 1 : Step 4
Explained Above
Step 5
Calling the transform( ) method of the simple imputer object replaces missing values in the array with the mean of the array, and returns the new transformed array.
However, sometimes we need to use the parameters that the model has learned from the input data to predict the output of new data rather than transforming the data.
That's when we need predictors.
3⃣ Predictors
- A predictor is an estimator that can use the learned parameters to predict the output of new data.
A linear regression model is an estimator and a predictor as it can learn the parameters from the data (slope, intercept) and can predict the output of new data.
Example 2: (building a linear regression model)
Step 1
We have input data (X) and target labels (y).
Step 2
We create a LinearRegression object to build our linear regression model.
👇👇
Step 3
We call the fit( ) method so that our model that can the parameters (intercept, slope) that best fit the model to the training data.
Step 4
We can access the learned parameters using the intercept_ attribute (intercept), and the coef_ attribute (slope).
Step 5
We use the predict method to predict the output of a new input instance.
Note that we can also use the score( ) method to evaluate the accuracy of our predictions.
Note:
Example 2 is taken from @aureliengeron's amazing book
"Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow: Concepts, Tools, and Techniques to Build Intelligent Systems"
That's it for this thread.
I know it's quite long, but learning these principles will make your life much easier when working with scikit-learn.
If you found this thread to be useful, kindly consider retweeting the first tweet, and for more content about #MachineLearning and #DataScience, follow me @ammaryh92
• • •
Missing some Tweet in this thread? You can try to
force a refresh
Pandas
- Pandas is probably one of the most powerful and flexible open source data analysis and manipulation tool available in any language.
- It provides a wide range of functions for data wrangling and cleaning.
resources:
1⃣ youtube.com/playlist?list=…
2⃣
NumPy (Numerical Python)
- NumPy is an open source project aiming to enable numerical computing with Python.
- It provides functions and methods for performing high level mathematical functions on multi-dimensional arrays and matrices.
The term Machine Learning sounds mysterious and confusing to a lot of people especially beginners.
In this thread, I will try to explain how does a machine learn, and why do we even need machine learning?
🧵👇
In pre-machine learning era, we had what is called "rule-based systems".
This basically means that we provide a machine with a bunch of instructions on how to perform a certain task.
For example, if we need to write a function that returns the square of a number.
With rule-based system, this is very easy. 1. First we define a function called Square, for example. 2. Square function takes X as an input, where X can be any number. 3. Square function multiplies X by itself (X **2). 4. Square function returns the result to the user.
If you are planning to get into machine learning, then you are likely to use scikit-learn, one of Python's most famous libraries.
In this thread, I will try to break down scikit-learn's API which could be intimidating in the beginning.
🧵👇 #MachineLearning
Estimators
- An estimator is any scikit-learn object that learns some parameters from data.
- All estimators implement "fit()" method to perform the estimation process.
- Estimators can also act as transformers or predictors.
Transformers
- They are estimators which use the parameters that they have learned to transform data.
- All transformers can implement "transform()" method to perform the transformation process.
I know this sounds vague, but it will become clearer after the following example.
Data Science learning roadmap
If you are looking to get into machine learning, I would like to make your life easier by listing some of my favorite resources in this thread 🧵👇 #MachineLearning
1⃣Python is the most common language for data science (even though there are other great languages like R, C++)
This playlist by @JustinMitchel is a great way to start. youtube.com/playlist?list=…
Bias/Variance analysis is one of the most important concepts in machine learning as it allows you to measure and improve the performance of your model.
🧵In this thread, I will discuss the basic idea behind it, so let's dive right in. #MachineLearning#ArtificialIntelligence
1⃣Bias (Underfitting)
What is bias?
In simple terms, bias is the difference between the model predictions and the actual values.
So if a model has a high bias, it means it has underfitted the training data. In other words, the model has a high training set error.
What causes a high bias?
Bias, or underfitting, mainly occurs when the model is too simple to understand the underlying structure of the training data, and so it misses the relevant relations between the input features and target outputs.