<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ilyas Ahmed  on Medium]]></title>
        <description><![CDATA[Stories by Ilyas Ahmed  on Medium]]></description>
        <link>https://medium.com/@ilyasbinsalih?source=rss-82ef671ed5f8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*GuDK8JShpWXvED4FDDcqpQ.jpeg</url>
            <title>Stories by Ilyas Ahmed  on Medium</title>
            <link>https://medium.com/@ilyasbinsalih?source=rss-82ef671ed5f8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 07:25:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ilyasbinsalih/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Ensemble Learning: A Surefire Way to Increase Accuracy]]></title>
            <link>https://ilyasbinsalih.medium.com/ensemble-learning-a-surefire-way-to-increase-accuracy-31f4381c7e4b?source=rss-82ef671ed5f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/31f4381c7e4b</guid>
            <category><![CDATA[bagging]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[model]]></category>
            <category><![CDATA[ensemble-learning]]></category>
            <dc:creator><![CDATA[Ilyas Ahmed ]]></dc:creator>
            <pubDate>Sun, 25 Jun 2023 09:56:16 GMT</pubDate>
            <atom:updated>2023-06-25T09:56:16.243Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V7OWni-_BftXPP29eZPCqQ.jpeg" /></figure><p>Ensemble learning is a machine learning technique that combines multiple models to create a more accurate and robust model than any of the individual models could be on its own. Ensemble learning methods can be used for both classification and regression tasks.</p><h3>Types of Ensemble Learning</h3><p>There are three main types of ensemble learning methods: <strong>bagging, boosting, and stacking</strong>.</p><h4>Bagging</h4><p>Bagging is a method that creates <em>multiple copies </em>of a <em>base model</em>, each trained on a different <em>bootstrap sample</em> of the training data. The bootstrap sample is a random sample of the training data with replacement, meaning that some data points may be included in multiple bootstrap samples. The predictions from the individual models are then combined to create a final prediction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/1*3-KM__549gAMLjTcK8qKeg.jpeg" /><figcaption>Diagram depicting Bagging Algorithm</figcaption></figure><p><em>For example</em>, <em>let’s say we have a training dataset with 100 data points. We can create 100 bootstrap samples, each with 100 data points. Each bootstrap sample would be a random sample of the training data with replacement, meaning that some data points may be included in multiple bootstrap samples. We can then train a base model on each bootstrap sample. Once we have trained 100 base models, we could combine their predictions to create a final prediction.</em></p><p>The code shown below will load the data, split it into training and test sets, create a bagging classifier, train the classifier, make predictions on the test set, and evaluate the classifier. The output of the code will be a classification report that shows the accuracy, precision, recall, and F1-score of the classifier.</p><pre>import numpy as np<br>from sklearn.ensemble import BaggingClassifier<br><br># Load the data<br>data = np.loadtxt(&quot;trees.csv&quot;, delimiter=&quot;,&quot;)<br><br># Split the data into training and test sets<br>X_train, X_test, y_train, y_test = train_test_split(data, data[:, -1], test_size=0.2)<br><br># Create a bagging classifier<br>clf = BaggingClassifier(base_estimator=DecisionTreeClassifier(), n_estimators=100, max_features=0.5)<br><br># Train the classifier<br>clf.fit(X_train, y_train)<br><br># Make predictions on the test set<br>y_pred = clf.predict(X_test)<br><br># Evaluate the classifier<br>print(classification_report(y_test, y_pred))</pre><p>We first load the data from a CSV file, then splits the data into training and test sets. A <strong>bagging classifier </strong>is then created with <strong>100 decision trees</strong> as base estimators, and the classifier is trained on the training data. The predictions for the test data are then made, and the classifier is evaluated using a classification report.</p><p>Here is an explanation of a few functions used in the code:</p><ul><li>The np.loadtxt() function loads the data from the CSV file.</li><li>The train_test_split() function splits the data into training and test sets.</li><li>The BaggingClassifier() class creates a bagging classifier.</li><li>The classification_report() function evaluates the classifier.</li></ul><h4>Boosting</h4><p>Boosting is a method that creates a series of models, each of which is trained on the same training data, but with the weights of the training data points updated after each model is trained. The weights of the training data points are updated so that the models are more likely to focus on the data points that were misclassified by the previous models. The predictions from the individual models are then combined to create a final prediction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*d13UkyoR3b8ICVTxUxXjpg.jpeg" /><figcaption>Diagram depicting Boosting Algorithm</figcaption></figure><p><em>For example, let’s say we have a training dataset with 100 data points. We can start by training a base model on the entire training dataset. The </em><strong><em>base model </em></strong><em>would make some predictions, and some of the predictions would be correct and some of the predictions would be incorrect. We can then update the weights of the training data points so that the model is more likely to focus on the data points that were misclassified. We could then train a </em><strong><em>second model</em></strong><em> on the updated training dataset. The second model would make some predictions, and some of the predictions would be correct and some of the predictions would be incorrect. We could then update the weights of the training data points again, and then train a </em><strong><em>third model</em></strong><em>, and so on. Once we have trained a series of models, we could combine their predictions to create a final prediction.</em></p><pre>import numpy as np<br>import pandas as pd<br>from sklearn.ensemble import AdaBoostClassifier<br>from sklearn.datasets import load_breast_cancer<br><br># Load the breast cancer dataset<br>cancer_data = load_breast_cancer()<br><br># Split the data into training and testing sets<br>X_train, X_test, y_train, y_test = train_test_split(cancer_data.data, cancer_data.target, test_size=0.25)<br><br># Create an AdaBoostClassifier model<br>adaboost = AdaBoostClassifier(n_estimators=100, learning_rate=0.1)<br><br># Fit the model to the training data<br>adaboost.fit(X_train, y_train)<br><br># Predict the labels for the test data<br>y_pred = adaboost.predict(X_test)<br><br># Calculate the accuracy of the model<br>accuracy = np.mean(y_pred == y_test)<br><br>print(&quot;Accuracy:&quot;, accuracy)</pre><p>The above shown code will first load the breast cancer dataset from the sklearn.datasets library. The dataset contains 569 samples with 30 features each. The features represent various measurements of breast cancer tumors, and the target variable is whether the tumor is malignant (1) or benign (0).</p><p>The code then splits the data into training and testing sets, with 75% of the data used for training and 25% used for testing. An <strong>AdaBoostClassifier </strong>model is then created with <strong>100 base learners </strong>and a<strong> learning rate of 0.1</strong>. The model is fit to the training data, and the labels for the test data are predicted. Finally, the accuracy of the model is calculated.</p><p>Running this code will print the accuracy of the model, which should be around 95%. This means that the model is able to correctly classify 95% of the test samples.</p><p>Here is an explanation of a few functions used in the code:</p><ul><li>The load_breast_cancer() function loads the breast cancer dataset from the sklearn.datasets library.</li><li>The train_test_split() function splits the data into training and testing sets.</li><li>The AdaBoostClassifier() class creates an AdaBoostClassifier model.</li></ul><p>I hope this example helps you understand how boosting works in Python.</p><h4>Stacking</h4><p>Stacking is a method that combines multiple models using a meta-model. The meta-model is trained on the predictions of the base models, and it uses this information to make a final prediction.</p><p>Stacking is a more complex ensemble learning method than bagging or boosting, but it can often achieve better results. <strong>This is because stacking can take advantage of the strengths of multiple models, and it can also compensate for the weaknesses of individual models.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/1*E4O8M-F1MFRh21DNjkktdA.jpeg" /><figcaption>Diagram depicting Stacking Algorithm</figcaption></figure><p><em>Here are the steps involved in stacking:</em></p><ol><li>Train a set of base models on the training data.</li><li>Use the base models to make predictions on the test data.</li><li>Train a meta-model (estimator) on the predictions of the base models.</li><li>Use the meta-model (estimator) to make predictions on the test data for the final output.</li></ol><p>Stacking can be used for both classification and regression tasks. It is a powerful technique that can be used to improve the accuracy of machine learning models.</p><pre>import numpy as np<br>from sklearn.ensemble import StackingClassifier<br>from sklearn.linear_model import LogisticRegression<br>from sklearn.neighbors import KNeighborsClassifier<br>from sklearn.tree import DecisionTreeClassifier<br>from sklearn.datasets import load_breast_cancer<br><br># Load the breast cancer dataset<br>cancer_data = load_breast_cancer()<br><br># Split the data into training and testing sets<br>X_train, X_test, y_train, y_test = train_test_split(cancer_data.data, cancer_data.target, test_size=0.25)<br><br># Create the base models<br>lr = LogisticRegression()<br>knn = KNeighborsClassifier()<br>dt = DecisionTreeClassifier()<br><br># Create the stacking classifier<br>stacking = StackingClassifier(estimators=[(&#39;lr&#39;, lr), (&#39;knn&#39;, knn), (&#39;dt&#39;, dt)], final_estimator=LogisticRegression())<br><br># Fit the stacking classifier to the training data<br>stacking.fit(X_train, y_train)<br><br># Predict the labels for the test data<br>y_pred = stacking.predict(X_test)<br><br># Calculate the accuracy of the model<br>accuracy = np.mean(y_pred == y_test)<br><br>print(&quot;Accuracy:&quot;, accuracy)</pre><p>In the code show above, the second line imports the sklearn.ensemble library, which contains the StackingClassifier class. The third line imports the sklearn.linear_model library, which contains the LogisticRegression class. The fourth line imports the sklearn.neighbors library, which contains the KNeighborsClassifier class. The fifth line imports the sklearn.tree library, which contains the DecisionTreeClassifier class.</p><p>The three estimators: <em>(‘lr’, lr), (‘knn’, knn), (‘dt’, dt)</em> are the base estimators that will predict on the train data provided. Then a meta learner (<strong>LogisticRegression </strong>in this example) or estimator is used to train on the predictions of the base estimators. The output we get from the meta estimator will be our final prediction.</p><h3>Advantages of Ensemble Learning</h3><p>Ensemble learning has a number of advantages over using a single model, including:</p><ul><li><strong>Reduced variance</strong>: It can reduce the variance of a model, which is the tendency of a model to make different predictions on different datasets. This is because the individual models in an ensemble are trained on different data, so they are less likely to be affected by noise in the data.</li><li><strong>Improved accuracy</strong>: It can improve the accuracy of a model, especially when the individual models in the ensemble are different types of models. This is because different models are likely to be good at different things, so by combining them, the ensemble can be better at all of the things that the individual models are good at.</li><li><strong>Robustness</strong>: It can make a model more robust to noise in the data or to changes in the data distribution. This is because the individual models in the ensemble are less likely to be affected by noise or changes in the data distribution, so the ensemble is less likely to be affected by them either.</li></ul><h3>Disadvantages of Ensemble Learning</h3><ul><li><strong>Comparatively complex:</strong> Ensemble models are often more complex than single models, which can make them more difficult to train and interpret.</li><li><strong>Computationally expensive:</strong> They are often more computationally expensive to train than single models.</li><li><strong>Not always better:</strong> They are not always better than using a single model. In some cases, a single model may be better than an ensemble model.</li><li><strong>Stability issues:</strong> They can be unstable, meaning that they can be sensitive to changes in the training data. This can make it difficult to get consistent results from ensemble learning models.</li><li><strong>Choosing the right models:</strong> When creating an ensemble learning model, it can be difficult to choose the right individual models to include in the ensemble. This is because different models are likely to be good at different things, and it is not always clear which models will work best together.</li></ul><p>Hope this helps in understanding the basics of Ensemble Learning. Feel free to suggest in-depth topics to consider in Ensemble Learning and I will be covering them here.</p><p><strong>For more exciting ML articles, please support me by following </strong><a href="https://medium.com/u/82ef671ed5f8"><strong>Ilyas Ahmed</strong></a></p><blockquote>Until next time, build away with ensemble methods!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31f4381c7e4b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Explainable AI (XAI): The Future of Trust in AI]]></title>
            <link>https://ilyasbinsalih.medium.com/explainable-ai-xai-the-future-of-trust-in-ai-e6ae4c21ec7e?source=rss-82ef671ed5f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6ae4c21ec7e</guid>
            <category><![CDATA[explainable-ai]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Ilyas Ahmed ]]></dc:creator>
            <pubDate>Tue, 06 Jun 2023 09:45:43 GMT</pubDate>
            <atom:updated>2023-06-06T09:45:43.676Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QP1DTKEJvJPlEWpE__Bl5A.jpeg" /></figure><h3>Introduction</h3><p>Artificial intelligence (AI) is rapidly becoming a part of our everyday lives. From self-driving cars to medical diagnosis, AI is being used to make decisions that have a significant impact on our lives. However, as AI systems become more complex, it is becoming increasingly difficult for humans to understand how they work and why they make the decisions they do. This lack of transparency can lead to a number of problems, including:</p><ul><li><strong>Lack of trust: </strong>If people don’t understand how an AI system works, they are less likely to trust it. This can make it difficult for AI systems to be adopted in a wide range of applications.</li><li><strong>Bias:</strong> AI systems can be biased, which can lead to unfair or inaccurate decisions. For example, an AI system that is used to make loan decisions may be biased against people of color, which could lead to people of color being less likely to get loans, even if they are qualified.</li><li><strong>Misuse:</strong> If people don’t understand how an AI system works, they may misuse it. For example, an AI system that is used to generate fake news could be used to spread misinformation.</li></ul><h3>Explainable AI (XAI)</h3><p>Explainable AI (XAI) is a set of techniques that allow humans to understand, interpret, and explain the decisions made by AI systems. XAI is important for a number of reasons, including:</p><ul><li><strong>Building trust:</strong> XAI can help users trust AI systems by providing them with insights into how the systems work and why they make the decisions they do. This can be especially important in situations where the decisions made by AI systems have a significant impact on people’s lives, such as in healthcare or finance.</li><li><strong>Identifying bias:</strong> XAI can help identify bias in AI systems. This is important because bias can lead to unfair or inaccurate decisions. For example, if an AI system is used to make loan decisions, and the system is biased against people of color, then people of color may be less likely to get loans, even if they are qualified.</li><li><strong>Improving performance:</strong> XAI can be used to improve the performance of AI systems. By understanding how the systems work, developers can make changes that improve the accuracy and fairness of the systems.</li></ul><h3>Types of XAI</h3><p>There are a number of different XAI techniques, each with its own strengths and weaknesses. Some of the most common XAI techniques include:</p><ul><li><strong>Feature importance:</strong> This technique identifies the features that are most important for making a prediction. This can be helpful for understanding why the system made a particular decision.</li><li><strong>Local explanations: </strong>This technique provides explanations for individual predictions. This can be helpful for understanding how the system made a particular decision for a specific data point.</li><li><strong>Counterfactual explanations:</strong> This technique shows how a prediction would change if one or more features were changed. This can be helpful for understanding how the system is sensitive to different features.</li></ul><h3>The Top XAI Libraries in Python</h3><p>There are a number of different XAI libraries in Python, each with its own strengths and weaknesses. Here are a few of the most popular XAI libraries:</p><ul><li><strong>SHAP</strong>: SHAP (SHapley Additive exPlanations) is a model-agnostic approach to explainability that uses Shapley values to explain the predictions of machine learning models. SHAP values are a measure of how much each feature contributes to a prediction.</li><li><strong>LIME</strong>: LIME (Local Interpretable Model-agnostic Explanations) is another model-agnostic approach to explainability that uses local surrogate models to explain the predictions of machine learning models. LIME explanations are local, which means that they only explain a single prediction.</li><li><strong>ALE</strong>: ALE (Attribution-LIME Explainer) is a combination of SHAP and LIME. ALE explanations are global, which means that they explain all of the predictions of a model. ALE explanations are also more interpretable than SHAP explanations.</li><li><strong>TensorFlow Explainability Toolkit</strong>: The TensorFlow Explainability Toolkit is a set of tools for explaining the predictions of TensorFlow models. The toolkit includes a number of different explainability methods, including SHAP, LIME, and ALE.</li><li><strong>SOptX</strong>: SOptX is a Python library for explaining the predictions of machine learning models. SOptX includes a number of different explainability methods, including SHAP, LIME, and ALE.</li></ul><p>When choosing an XAI library, it is important to consider the following factors:</p><ul><li><strong>The type of model you are using: </strong>Some XAI libraries are only compatible with certain types of models. For example, SHAP is only compatible with models that have a single output.</li><li><strong>The level of detail you need:</strong> Some XAI libraries provide more detailed explanations than others. For example, ALE explanations are more detailed than SHAP explanations.</li><li><strong>The ease of use:</strong> Some XAI libraries are easier to use than others. For example, TensorFlow Explainability Toolkit is more difficult to use than SOptX.</li></ul><h3>Challenges of XAI</h3><p>Despite the benefits of XAI, there are a number of challenges that need to be addressed before XAI can be widely adopted. Some of the challenges of XAI include:</p><ul><li><strong>Complexity:</strong> XAI techniques can be complex and difficult to understand. This can make it difficult for developers to implement XAI techniques in their AI systems.</li><li><strong>Cost: </strong>XAI techniques can be expensive to implement. This can make it difficult for small businesses and startups to adopt XAI.</li><li><strong>Acceptance: </strong>Some people may not be comfortable with the idea of AI systems that are able to explain their decisions. This could make it difficult for AI systems to be adopted in some applications.</li></ul><h3>Python Code Using XAI</h3><p>Here we have used a sample dataset from Kaggle to predict the price of houses based on a number of features. We will be using the <strong>LIME </strong>library to explain how the model works to predict a certain value. The dataset shown below gives a clear picture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M8XQdSHqQXmA-v77oQlTVw.png" /><figcaption>House Price Prediction Dataset from <a href="https://www.kaggle.com/datasets/yasserh/housing-prices-dataset">Kaggle</a></figcaption></figure><p>We can see from the dataset that there are a lot of features that define the price of the house. In this example, we will use a few features to show how the LIME explainer depicts the way a prediction is reached.</p><pre>import lime<br>import lime.lime_tabular<br><br>explainer = lime.lime_tabular.LimeTabularExplainer(X_train.values, feature_names=X_train.columns.values.tolist(),<br>                                                  class_names=[&#39;price&#39;], verbose=True, mode=&#39;regression&#39;)<br><br>record_num = 7<br>exp = explainer.explain_instance(X_test.values[record_num], model.predict, num_features=6)<br><br>exp.show_in_notebook(show_table=True)</pre><p>The code given above will import the <strong>Lime </strong>and <strong>LimeTabular </strong>libraries, create a <strong>LimeTabularExplainer </strong>object, explain a single prediction, and show the explanation in a notebook. The output of the code will be a table that shows the importance of each feature for the prediction.</p><p>Here is a more detailed explanation of the code:</p><ul><li>The import lime and import lime.lime_tabular lines import the <strong>Lime </strong>and <strong>LimeTabular </strong>libraries. These libraries will be used to create the Lime explainer.</li><li>The explainer = lime.lime_tabular.LimeTabularExplainer(X_train.values, feature_names=X_train.columns.values.tolist(), class_names=[&#39;price&#39;], verbose=True, mode=&#39;regression&#39;) line creates a <strong>LimeTabularExplainer </strong>object. The X_train.values parameter specifies the training data. The feature_names parameter specifies the names of the features. The class_names parameter specifies the names of the classes. The verbose parameter specifies whether or not the explainer should print status messages. The mode parameter specifies the mode of the explainer. In this case, the mode is regression, which means that the explainer will be used to explain a regression prediction.</li><li>The record_num = 7 line specifies the record number that will be explained.</li><li>The exp = explainer.explain_instance(X_test.values[record_num], model.predict, num_features=6) line explains a single prediction. The X_test.values[record_num] parameter specifies the data point that the explanation will be generated for. The model.predict function is used to predict the value of the data point. The num_features parameter specifies the number of features that the explainer will consider.</li><li>The exp.show_in_notebook(show_table=True) line shows the explanation in a notebook. The show_table parameter specifies whether or not the explanation should be shown as a table.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TQsesmUSPIw6F1kzXDBdMg.png" /><figcaption>LIME Explainer output in Jupyter Notebook</figcaption></figure><p>The above image depicts the following:</p><ul><li>The house price was predicted as 6466502.44 USD</li><li>The variables <em>bathrooms</em>, <em>basement </em>and <em>stories </em>have a <strong>positive </strong>influence on the prediction</li><li>The variables <em>airconditioning</em>, <em>hotwaterheating </em>and <em>parking </em>have a <strong>negative </strong>impact on the prediction</li></ul><p>A lot more can be done with these powerful XAI libraries. A small example in depicted here.</p><h3>The Future of XAI</h3><p>Despite the challenges, XAI is a rapidly growing field, and there are many new techniques being developed all the time. As XAI techniques improve, they will become increasingly important for building trust in AI systems, identifying bias, and improving performance.</p><h3>Conclusion</h3><p>Explainable AI is a critical technology that will help to ensure that AI systems are trustworthy, fair, and accurate. As XAI techniques continue to improve, we can expect to see a wide range of applications for XAI in a variety of industries. It is a rapidly growing field and the techniques allow humans to understand, interpret, and explain the decisions made by AI systems. This can help to build trust with users, identify bias in systems, and improve the performance of systems. Python is a popular language for developing XAI systems. There are a number of XAI libraries available in Python, including SHAP, LIME, and ALE. These libraries can be used to explain the predictions of a wide variety of AI models.</p><p><strong>For more exciting ML articles, please support me by following </strong><a href="https://medium.com/u/82ef671ed5f8"><strong>Ilyas Ahmed</strong></a></p><blockquote>Until next time, build AI models away with XAI!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6ae4c21ec7e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sktime: The One-Stop Shop for Time Series Analysis in Python]]></title>
            <link>https://ilyasbinsalih.medium.com/sktime-the-one-stop-shop-for-time-series-analysis-in-python-183902130039?source=rss-82ef671ed5f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/183902130039</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[time-series-analysis]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[forecasting]]></category>
            <dc:creator><![CDATA[Ilyas Ahmed ]]></dc:creator>
            <pubDate>Sun, 04 Jun 2023 05:24:38 GMT</pubDate>
            <atom:updated>2023-06-06T10:12:21.563Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7vnhq64q-BKvBUtZzPE__g.jpeg" /></figure><h3>Introduction</h3><p><strong>Sktime </strong>is an open-source Python library for time series analysis. It provides a unified interface for multiple time series learning tasks, including forecasting, classification, regression, clustering, annotation, and dimensionality reduction. Sktime also provides interfaces to related libraries, such as scikit-learn, statsmodels, tsfresh, PyOD, and fbprophet.</p><p>It is designed to be easy to use, flexible, and modular. It offers scikit-learn compatible interfaces and model composition tools, with the goal to make the time series analysis ecosystem more usable and interoperable as a whole. Sktime is built and sustained by an open, diverse, and self-governing community.</p><h4>Here are some of the features:</h4><ul><li>Unified interface for multiple time series learning tasks</li><li>Scikit-learn compatible interfaces</li><li>Model composition tools</li><li>Interfaces to related libraries</li><li>Easy to use, flexible, and modular</li><li>Built and sustained by an open, diverse, and self-governing community</li></ul><h4>What All Can Sktime be Used For?</h4><ul><li><strong>Time Series Forecasting</strong>: Sktime can be used to forecast future values of time series data. This can be useful for planning, budgeting, and other decision-making tasks.</li><li><strong>Time Series Classification</strong>: Sktime can be used to classify time series data into different categories. This can be useful for fraud detection, medical diagnosis, and other applications.</li><li><strong>Time Series Regression</strong>: Sktime can be used to predict the value of a time series variable based on other time series variables. This can be useful for financial forecasting, weather prediction, and other applications.</li><li><strong>Time Series Clustering</strong>: Sktime can be used to cluster time series data into groups. This can be useful for identifying patterns in data and for reducing the dimensionality of data.</li><li><strong>Time Series Annotation</strong>: Sktime can be used to annotate time series data with labels or metadata. This can be useful for understanding the meaning of data and for making it more accessible to others.</li><li><strong>Dimensionality reduction</strong>: Sktime can be used to reduce the dimensionality of time series data. This can be useful for making data easier to visualize and for improving the performance of machine learning algorithms.</li></ul><h4>Examples of Classifiers Available in Sktime:</h4><p>Sktime is a powerful tool for time series analysis. It provides a comprehensive set of tools for a wide range of tasks, and it is easy to use and learn. If you are interested in time series analysis, sktime is a great resource. It provides a variety of classifiers for time series data, including:</p><ul><li><strong>Distance-based classifiers</strong>: These classifiers use distance metrics to compare time series. Examples include the Elastic Ensemble (EE), KNN Time Series Classifier, Proximity Forest, Proximity Stump, and Proximity Tree.</li><li><strong>Interval-based classifiers</strong>: These classifiers use intervals to represent time series. Examples include the Time Series Forest (TSF), Random Interval Spectral Ensemble (RISE), Supervised Time Series Forest (STSF), Canonical Interval Forest (CIF), and Diverse Representation Canonical Interval Forest (DrCIF).</li><li><strong>Dictionary-based classifiers</strong>: These classifiers use dictionaries to represent time series. Examples include the Bag-of-Symbols (BoS) Classifier and the Bag-of-Patterns (BoP) Classifier.</li><li><strong>Deep learning classifiers</strong>: These classifiers use deep learning models to represent time series. Examples include the Convolutional Neural Network (CNN) Classifier and the Recurrent Neural Network (RNN) Classifier.</li></ul><p>The choice of classifier depends on the specific time series data and the desired accuracy. Distance-based classifiers are generally fast and easy to train, but they may not be as accurate as interval-based or dictionary-based classifiers. Interval-based and dictionary-based classifiers are more accurate, but they may be slower to train. Deep learning classifiers can be very accurate, but they may require a large amount of data to train.</p><h3>Python Code for Time Series Forecasting</h3><p>To get started with sktime, simply install it using pip:</p><pre>pip install sktime</pre><p>Then head over to your preferred IDE and start experimenting with the powerful library. Here is an example of using a regression algorithm to solve a forecasting task:</p><pre>import numpy as np<br>from sktime.datasets import load_airline<br>from sktime.forecasting.compose import make_reduction<br>from sklearn.ensemble import RandomForestRegressor<br>from sktime.forecasting.model_selection import temporal_train_test_split<br>from sktime.performance_metrics.forecasting import MeanAbsolutePercentageError<br><br>y = load_airline()<br>y_train, y_test = temporal_train_test_split(y)<br><br># forecasting horizon<br>fh = np.arange(1, len(y_test) + 1)  <br><br>regressor = RandomForestRegressor()<br>forecaster = make_reduction(<br>    regressor,<br>    strategy=&quot;recursive&quot;,<br>    window_length=12,<br>)<br><br>forecaster.fit(y_train)<br><br>y_pred = forecaster.predict(fh)<br><br>smape = MeanAbsolutePercentageError()<br>smape(y_test, y_pred)<br>&gt;&gt;&gt; 0.1261192310833735</pre><p><em>It is as easy as that! So don’t wait for anyone. Forecast away!</em></p><p>The documentation of sktime is also very comprehensive with all the details provided for each and every implementation of different classifiers available. The link is given below for reference:<br><a href="https://www.sktime.net/en/latest/api_reference/base.html">https://www.sktime.net/en/latest/api_reference/base.html</a></p><p>For more exciting ML articles, please support me by following <a href="https://medium.com/u/82ef671ed5f8">Ilyas Ahmed</a></p><blockquote>Until next time, happy forecasting.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=183902130039" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Hard and Soft Voting in Machine Learning?]]></title>
            <link>https://ilyasbinsalih.medium.com/what-is-hard-and-soft-voting-in-machine-learning-2652676b6a32?source=rss-82ef671ed5f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/2652676b6a32</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[voting]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ensemble-learning]]></category>
            <dc:creator><![CDATA[Ilyas Ahmed ]]></dc:creator>
            <pubDate>Wed, 31 May 2023 07:24:39 GMT</pubDate>
            <atom:updated>2023-05-31T07:24:39.109Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WH5jFH4jJVgfe6T9rGVBig.png" /></figure><h3>Introduction</h3><p>Hard voting and soft voting are two different ways to combine the predictions of multiple classifiers in ensemble machine learning algorithms.</p><p><strong>Hard voting is the simplest approach. Each classifier makes a prediction, and the ensemble’s prediction is simply the majority vote. </strong>For example, if three classifiers predict that an image is of a cat and one classifier predicts that it is of a deer, the ensemble’s prediction will be that the image is of a cat.</p><p><strong>Soft voting takes into account the confidence of each classifier’s prediction. Each classifier assigns a probability to each class, and the ensemble’s prediction is the class with the highest total probability.</strong> For example, if one classifier predicts that an image is of a cat with a probability of 0.9 and another classifier predicts that it is of a deer with a probability of 0.1, the ensemble’s prediction will be that the image is of a cat.</p><p><em>Hard voting is simpler to implement, but it can be less accurate than soft voting. This is because hard voting ignores the confidence of each classifier’s prediction. Soft voting is more accurate, but it is also more complex to implement. The best approach to use will depend on the specific application. If accuracy is the most important factor, then soft voting is the better choice. However, if simplicity is more important, then hard voting may be a better option.</em></p><h3>Hard Voting</h3><h4>How does Hard Voting Work?</h4><p>Hard voting is a simple algorithm that can be used to combine the predictions of multiple classifiers. The algorithm works by first having each classifier make a prediction. The ensemble’s prediction is then simply the majority vote of the individual classifiers.</p><p>For example, let’s say we have three classifiers, each of which is trained to classify images of <strong>cats (0) and deers (1)</strong>. The first classifier predicts that an image is of a cat, the second classifier predicts that it is of a deer, and the third classifier is cat. The ensemble’s prediction would be that the image is of a <strong>cat</strong>, because <strong>two </strong>of the <strong>three </strong>classifiers made that prediction. The image depicted below shows the same.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*MX_lPIE0bcFrFytg2KAksg.png" /><figcaption>Depiction of Hard Voting in Ensemble Machine Learning</figcaption></figure><h4>Advantages of Hard Voting</h4><p>Hard voting has several advantages over other ensemble learning algorithms. First, it is very simple to implement. Second, it is very effective. Third, it can be used with any type of classifier.</p><p>The simplicity of hard voting makes it a popular choice for machine learning practitioners. Hard voting is also very effective, and can often outperform other ensemble learning algorithms. Finally, hard voting can be used with any type of classifier, making it a versatile tool.</p><h4>Disadvantages of Hard Voting</h4><p>Hard voting also has some disadvantages. First, it can be less accurate than soft voting, which takes into account the confidence of each classifier’s prediction. Second, hard voting can be less robust to noise in the data.</p><p>The accuracy of hard voting can be limited by the fact that it ignores the confidence of each classifier’s prediction. This means that hard voting can be more likely to make mistakes when the individual classifiers are not very confident in their predictions.</p><p>Hard voting can also be less robust to noise in the data. This is because hard voting is based on the majority vote of the individual classifiers. If the data is noisy, it is more likely that the majority vote will be incorrect.</p><h4>Python Code — Hard Voting</h4><p>The sample code first creates a list of classifiers. It then creates a voting classifier and trains it on the training data. Finally, it makes predictions on the test data and evaluates the accuracy.</p><p>The VotingClassifier class in scikit-learn can be used to combine the predictions of multiple classifiers. The <strong>voting </strong>parameter can be set to &#39;<strong>hard</strong>&#39; to use hard voting.</p><pre>import numpy as np<br>from sklearn.ensemble import VotingClassifier<br><br># Create a list of classifiers.<br>classifiers = [<br>    KNeighborsClassifier(n_neighbors=5),<br>    RandomForestClassifier(n_estimators=100),<br>    DecisionTreeClassifier()<br>]<br><br># Create a voting classifier.<br>voting_clf = VotingClassifier(estimators=classifiers, voting=&#39;hard&#39;)<br><br># Train the voting classifier.<br>voting_clf.fit(X_train, y_train)<br><br># Make predictions.<br>y_pred = voting_clf.predict(X_test)<br><br># Evaluate the accuracy.<br>print(accuracy_score(y_test, y_pred))</pre><h3>Soft Voting</h3><h4>How does Soft Voting Work?</h4><p>Soft voting is an algorithm that can be used to combine the predictions of multiple classifiers using the probability of predictions. The algorithm works by first having each classifier assign a probability to each class. The ensemble’s prediction is then simply the class with the highest total probability.</p><p>For example, let’s say we have three classifiers, each of which is trained to classify images of <strong>cats (1) and deers (0)</strong>. The first classifier predicts that the image is of a cat with a probability of 0.7 and deer with a probability of 0.3, the second classifier predicts that the image is of a cat with a probability of 0.4 and deer with a probability of 0.6, and the third classifier predicts that the image is of a cat with a probability of 0.9 and deer with a probability of 0.1. The ensemble’s prediction would be that the image is of a <strong>cat</strong>, because the total probability of the cat class is (<strong>0.7 + 0.4 + 0.9) / 3 = 0.666 </strong>and the probability of deer class is (<strong>0.3 + 0.6 + 0.1) / 3 = 0.333</strong>. The image depicted below shows the same.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*jWDS7vyoVmp3__sPALq64g.png" /><figcaption>Depiction of Soft Voting in Ensemble Machine Learning</figcaption></figure><p>Soft voting is a simple algorithm, but it can be very effective. This is because it takes advantage of the fact that multiple classifiers can often make more accurate predictions than a single classifier.</p><h4>Advantages of Soft Voting</h4><p>Soft voting has several advantages over hard voting. First, it is more accurate than hard voting. Second, it is more robust to noise in the data. Third, it can be used with any type of classifier.</p><p>The accuracy of soft voting is due to the fact that it takes into account the confidence of each classifier’s prediction. This means that soft voting is less likely to make mistakes when the individual classifiers are not very confident in their predictions.</p><p>Soft voting is also more robust to noise in the data. This is because soft voting is based on the total probability of each class. If the data is noisy, it is more likely that the total probability of the correct class will be higher than the total probability of the incorrect classes.</p><p>Finally, soft voting can be used with any type of classifier. This is because soft voting does not require the classifiers to be trained in the same way.</p><h4>Disadvantages of Soft Voting</h4><p>Soft voting also has some disadvantages. First, it is more complex to implement than hard voting. Second, it can be less efficient than hard voting. The complexity of soft voting is due to the fact that it requires each classifier to assign a probability to each class. This can be a time-consuming process, especially if there are a large number of classes.</p><h4>Python Code — Soft Voting</h4><p>The sample code shown below creates a list of classifiers. It then creates a voting classifier and trains it on the training data. Finally, it makes predictions on the test data and evaluates the accuracy.</p><p>The VotingClassifier class in scikit-learn can be used to combine the predictions of multiple classifiers. The <strong>voting </strong>parameter can be set to &#39;<strong>soft</strong>&#39; to use soft voting. In soft voting, the predictions of each classifier are weighted by their confidence scores. The class with the highest weighted sum is then chosen as the ensemble’s prediction.</p><pre>import numpy as np<br>from sklearn.ensemble import VotingClassifier<br><br># Create a list of classifiers.<br>classifiers = [<br>    KNeighborsClassifier(n_neighbors=5),<br>    RandomForestClassifier(n_estimators=100),<br>    DecisionTreeClassifier()<br>]<br><br># Create a voting classifier.<br>voting_clf = VotingClassifier(estimators=classifiers, voting=&#39;soft&#39;)<br><br># Train the voting classifier.<br>voting_clf.fit(X_train, y_train)<br><br># Make predictions.<br>y_pred = voting_clf.predict_proba(X_test)<br><br># Evaluate the accuracy.<br>print(accuracy_score(y_test, y_pred.argmax(axis=1)))</pre><h3>Conclusion</h3><p>Hard voting is simpler to implement, but it can be less accurate than soft voting. This is because hard voting ignores the confidence of each classifier’s prediction. Soft voting is more accurate, but it is also more complex to implement.</p><p>The best approach to use will depend on the specific application. If accuracy is the most important factor, then soft voting is the better choice. However, if simplicity is more important, then hard voting may be a better option.</p><h4>Hard voting:</h4><ul><li>Simple to implement</li><li>Less accurate than soft voting</li><li>Better for applications where simplicity is more important</li></ul><h4>Soft voting:</h4><ul><li>More complex to implement</li><li>More accurate than hard voting</li><li>Better for applications where accuracy is more important</li></ul><blockquote>Here are some examples of when hard voting and soft voting might be used:</blockquote><h4>Hard voting:</h4><ul><li>A spam filter that uses multiple classifiers to identify spam emails</li><li>A fraud detection system that uses multiple classifiers to identify fraudulent transactions</li><li>A medical diagnosis system that uses multiple classifiers to identify diseases</li></ul><h4>Soft voting:</h4><ul><li>A stock market prediction system that uses multiple classifiers to predict stock prices</li><li>A weather forecasting system that uses multiple classifiers to predict the weather</li><li>A climate change prediction system that uses multiple classifiers to predict the effects of climate change</li></ul><p>Ultimately, the best way to decide which approach to use is to experiment with both hard voting and soft voting and see which one performs better on your specific data set.</p><blockquote>Follow me more for exciting topics on Machine Learning <a href="https://medium.com/u/82ef671ed5f8">Ilyas Ahmed</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2652676b6a32" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What are ACF and PACF Plots in Time Series Analysis?]]></title>
            <link>https://ilyasbinsalih.medium.com/what-are-acf-and-pacf-plots-in-time-series-analysis-cb586b119c5d?source=rss-82ef671ed5f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb586b119c5d</guid>
            <category><![CDATA[pacf]]></category>
            <category><![CDATA[time-series-analysis]]></category>
            <category><![CDATA[forecasting]]></category>
            <category><![CDATA[acf]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Ilyas Ahmed ]]></dc:creator>
            <pubDate>Sun, 28 May 2023 10:01:47 GMT</pubDate>
            <atom:updated>2023-05-31T07:30:12.520Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i6P1AyK3N8RylfKYxb0WSA.png" /></figure><p>In time series analysis, ACF and PACF plots are two of the most important tools for identifying the underlying structure of a time series. The ACF plot shows the correlation of a time series with itself at different lags, while the PACF plot shows the correlation of a time series with itself at different lags, after removing the effects of the previous lags.</p><p><strong>Autocorrelation Function (ACF)</strong></p><p>The ACF plot is a graphical representation of the correlation of a time series with itself at different lags. The correlation coefficient is a measure of how closely two variables are related. A correlation coefficient of 1 indicates a perfect positive relationship, while a correlation coefficient of -1 indicates a perfect negative relationship. A correlation coefficient of 0 indicates no relationship between the two variables.</p><p>The ACF plot can be used to identify the order of an AR model. The order of an AR model is the number of lags that are included in the model. The ACF plot will show spikes at the lags that are included in the model.</p><p><strong>Partial Autocorrelation Function (PACF)</strong></p><p>The PACF plot is a graphical representation of the correlation of a time series with itself at different lags, after removing the effects of the previous lags. The PACF plot can be used to identify the order of an MA model. The order of an MA model is the number of lags that are included in the model. The PACF plot will show spikes at the lags that are included in the model.</p><h3>AR, MA and ARMA Models</h3><p><strong>AR Models</strong></p><p>An autoregressive (AR) model is a type of time series model that uses the past values of a time series to predict future values. AR models are a popular choice for forecasting time series data because they are relatively simple to understand and implement.</p><p>An AR model is typically written as:</p><pre>y_t = c + \phi_1 y_{t-1} + \phi_2 y_{t-2} + ... + \phi_p y_{t-p} + \epsilon_t</pre><p>where:</p><ul><li><em>yt</em>​ is the value of the time series at time <em>t</em></li><li><em>c</em> is the intercept term</li><li><em>ϕ</em>1​,<em>ϕ</em>2​,…,<em>ϕp</em>​ are the model coefficients</li><li><em>ϵt</em>​ is the error term</li></ul><p>The model coefficients, <em>ϕ</em>1​,<em>ϕ</em>2​,…,<em>ϕp</em>​, are estimated using a variety of methods, such as least squares estimation. Once the model coefficients are estimated, the model can be used to predict future values of the time series. AR models are a versatile tool that can be used to forecast a wide variety of time series data. The accuracy of an AR model will depend on the characteristics of the time series data.</p><p>Here are some of the advantages of using AR models:</p><ul><li>They are relatively simple to understand and implement.</li><li>They can be used to forecast a wide variety of time series data.</li><li>They are relatively efficient, meaning that they require a relatively small amount of data to train.</li></ul><p>Here are some of the disadvantages of using AR models:</p><ul><li>They can be sensitive to outliers.</li><li>They may not be accurate for time series data that is not stationary.</li><li>They may not be able to capture long-term trends.</li></ul><p><strong>MA Models</strong></p><p>A moving average (MA) model is a type of time series model that uses the past errors of a time series to predict future values. MA models are a popular choice for forecasting time series data because they are relatively simple to understand and implement.</p><p>An MA model is typically written as:</p><pre>y_t = c + \theta_1 \epsilon_{t-1} + \theta_2 \epsilon_{t-2} + … + \theta_q \epsilon_{t-q} + \epsilon_t</pre><p>where:</p><ul><li><em>yt</em>​ is the value of the time series at time <em>t</em></li><li><em>c</em> is the intercept term</li><li><em>θ</em>1​,<em>θ</em>2​,…,<em>θq</em>​ are the model coefficients</li><li><em>ϵt</em>​ is the error term</li></ul><p>The model coefficients, <em>θ</em>1​,<em>θ</em>2​,…,<em>θq</em>​, are estimated using a variety of methods, such as least squares estimation. Once the model coefficients are estimated, the model can be used to predict future values of the time series. It is important to note that MA models are not always accurate. The accuracy of an MA model will depend on the characteristics of the time series data.</p><p>Here are some of the advantages of using MA models:</p><ul><li>They are relatively simple to understand and implement.</li><li>They can be used to forecast a wide variety of time series data.</li><li>They are relatively efficient, meaning that they require a relatively small amount of data to train.</li></ul><p>Here are some of the disadvantages of using MA models:</p><ul><li>They can be sensitive to outliers.</li><li>They may not be accurate for time series data that is not stationary.</li><li>They may not be able to capture long-term trends.</li></ul><p>MA models are often used in combination with AR models to create ARMA models. ARMA models are more complex than AR or MA models, but they can be more accurate for certain types of time series data.</p><p><strong>ARMA Models</strong></p><p>ARMA models are a combination of AR and MA models. The order of an ARMA model is the sum of the order of the AR model and the order of the MA model. It uses both the past values and the past errors of a time series to predict future values. ARMA models are a popular choice for forecasting time series data because they are relatively simple to understand and implement, and they can be more accurate than AR or MA models for certain types of time series data.</p><h3><strong>Interpreting ACF and PACF Plots</strong></h3><p>The ACF and PACF plots can be used to identify the underlying structure of a time series. The following are some general guidelines for interpreting ACF and PACF plots:</p><ul><li><em>If the ACF plot shows spikes at the first few lags, then an AR model may be appropriate.</em></li><li><em>If the PACF plot shows spikes at the first few lags, then an MA model may be appropriate.</em></li><li><em>If the ACF and PACF plots both show spikes at the first few lags, then an ARMA model may be appropriate.</em></li></ul><p>It is important to note that the ACF and PACF plots are just a starting point for identifying the underlying structure of a time series. The final model should be chosen based on a combination of the ACF and PACF plots, as well as other factors such as the Akaike Information Criterion (AIC) and the Bayesian Information Criterion (BIC).</p><h3>Python Code to Display ACF and PACF Plots</h3><p>In the below code a sample <strong>data.csv</strong> file is loaded and then the PACF and ACF plots are displayed using the fuction <strong>acf </strong>and <strong>pacf </strong>from <strong>statsmodels.tsa.stattools.</strong></p><pre>import pandas as pd<br>import matplotlib.pyplot as plt<br>from statsmodels.tsa.stattools import acf, pacf<br><br># Load the data<br>data = pd.read_csv(&#39;data.csv&#39;, index_col=&#39;Date&#39;)<br><br># Plot the ACF and PACF<br>plt.subplot(211)<br>plt.plot(acf(data[&#39;Value&#39;]))<br>plt.axhline(0, color=&#39;black&#39;)<br>plt.axhline(1.96/np.sqrt(len(data)), color=&#39;red&#39;, linestyle=&#39;dashed&#39;)<br>plt.axhline(-1.96/np.sqrt(len(data)), color=&#39;red&#39;, linestyle=&#39;dashed&#39;)<br>plt.title(&#39;ACF&#39;)<br><br>plt.subplot(212)<br>plt.plot(pacf(data[&#39;Value&#39;]))<br>plt.axhline(0, color=&#39;black&#39;)<br>plt.axhline(1.96/np.sqrt(len(data)), color=&#39;red&#39;, linestyle=&#39;dashed&#39;)<br>plt.axhline(-1.96/np.sqrt(len(data)), color=&#39;red&#39;, linestyle=&#39;dashed&#39;)<br>plt.title(&#39;PACF&#39;)<br><br>plt.show()</pre><p><strong>Conclusion</strong></p><p>The ACF and PACF plots are two of the most important tools for identifying the underlying structure of a time series. <strong>The ACF plot shows the correlation of a time series with itself at different lags, while the PACF plot shows the correlation of a time series with itself at different lags, after removing the effects of the previous lags</strong>. The ACF and PACF plots can be used to identify the order of AR, MA, and ARMA models.</p><blockquote>Follow me more for exciting topics on Machine Learning <a href="https://medium.com/u/82ef671ed5f8">Ilyas Ahmed</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb586b119c5d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Google Bard?]]></title>
            <link>https://ilyasbinsalih.medium.com/what-is-google-bard-7c2a8a2d44eb?source=rss-82ef671ed5f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/7c2a8a2d44eb</guid>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[generative-ai]]></category>
            <category><![CDATA[benefits]]></category>
            <category><![CDATA[bard-ai]]></category>
            <dc:creator><![CDATA[Ilyas Ahmed ]]></dc:creator>
            <pubDate>Thu, 25 May 2023 10:36:19 GMT</pubDate>
            <atom:updated>2023-05-25T10:36:41.835Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oK83h7hKYDnwPngKkIobew.png" /></figure><h3>Introduction</h3><p>Bard is a large language model (LLM) from Google AI, trained on a massive dataset of text and code. It can generate text, translate languages, write different kinds of creative content, and answer your questions in an informative way. Bard is still under development, but it has learned to perform many kinds of tasks, including:</p><ul><li>Trying its level best to follow your instructions and complete your requests thoughtfully.</li><li>Using its knowledge to answer your questions in a comprehensive and informative way, even if they are open ended, challenging, or strange.</li><li>Generating different creative text formats of text content, like poems, code, scripts, musical pieces, email, letters, etc. I will try my best to fulfill all your requirements.</li></ul><p>A few points are discussed regarding the uses of Bard and how it can be used to improve people’s lives. Some of the limitations of Bard and how to avoid them are also discussed.</p><h3>Uses of Bard</h3><p>Bard can be used for a variety of purposes, including:</p><ul><li><strong>Generating text</strong>: Bard can be used to generate text for a variety of purposes, such as writing blog posts, articles, or even books. It can also be used to generate creative content, such as poems, stories, or songs.</li><li><strong>Translating languages</strong>: Bard can be used to translate languages, both from English to other languages and from other languages to English. This can be useful for travel, business, or simply to learn about other cultures.</li><li><strong>Writing different kinds of creative content</strong>: Bard can be used to write different kinds of creative content, such as poems, stories, or songs. This can be a fun way to express yourself or to learn new skills.</li><li><strong>Answering your questions in an informative way</strong>: Bard can be used to answer your questions in an informative way, even if they are open ended, challenging, or strange. This can be a great way to learn new things or to get help with a problem.</li></ul><h3>Limitations of Bard</h3><p>Bard is still under development, so it has some limitations. These limitations include:</p><ul><li>Bard may not always be accurate: Bard is trained on a massive dataset of text and code, but it is still possible for it to make mistakes. This is especially true when it is asked to generate text on a topic that it has not been trained on.</li><li>Bard may not always be creative: Bard can generate creative content, but it is still possible for it to be repetitive or unoriginal. This is especially true when it is asked to generate text on a topic that it has not been trained on.</li><li>Bard may not always be helpful: Bard can be used to answer your questions in an informative way, but it is still possible for it to give you incorrect or unhelpful information. This is especially true when it is asked to answer a question that it has not been trained on.</li></ul><h3>How to Avoid Limitations of Bard</h3><p>There are a few things you can do to avoid the limitations of Bard:</p><ul><li><strong>Be specific in your requests</strong>: When you ask Bard to do something, be as specific as possible. This will help Bard to understand what you want and to generate the best possible results.</li><li><strong>Provide Bard with context</strong>: When you ask Bard to do something, provide it with as much context as possible. This will help Bard to understand the situation and to generate the best possible results.</li><li><strong>Be patient</strong>: Bard is still under development, so it may take some time for it to learn how to do things perfectly. Be patient and give Bard time to learn.</li></ul><h3>Conclusion</h3><p>Bard is a powerful tool that can be used for a variety of purposes. It can be used to generate text, translate languages, write different kinds of creative content, and answer your questions in an informative way. However, Bard is still under development, so it has some limitations. These limitations can be avoided by being specific in your requests, providing Bard with context, and being patient.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7c2a8a2d44eb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Fix Imbalanced Data]]></title>
            <link>https://ilyasbinsalih.medium.com/how-to-fix-imbalanced-data-60b905afc56c?source=rss-82ef671ed5f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/60b905afc56c</guid>
            <category><![CDATA[smote]]></category>
            <category><![CDATA[imbalanced-data]]></category>
            <category><![CDATA[oversampling]]></category>
            <category><![CDATA[ensemble-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Ilyas Ahmed ]]></dc:creator>
            <pubDate>Mon, 22 May 2023 06:22:31 GMT</pubDate>
            <atom:updated>2023-05-22T06:31:13.724Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Fix Imbalanced Data (with Python Code for SMOTE)</h3><h3>Introduction:</h3><p>Imbalanced datasets are a common problem in machine learning. They occur when there is a significant difference in the number of examples in each class. This can make it difficult to train a model that can accurately predict the minority class.</p><p>There are a number of techniques that can be used to fix imbalanced datasets. Some of the most common methods include:</p><ul><li><strong>Oversampling</strong>: This involves duplicating the minority class examples so that they are more evenly represented in the dataset. This can help to prevent the model from overfitting to the majority class.</li><li><strong>Undersampling</strong>: This involves removing majority class examples from the dataset so that the classes are more evenly represented. This can help to prevent the model from underfitting to the minority class.</li><li><strong>Weighting</strong>: This involves assigning different weights to the different classes when training the model. This can help to ensure that the model pays attention to the minority class examples.</li><li><strong>Ensemble learning</strong>: This involves training multiple models on different subsets of the data and then combining their predictions. This can help to improve the overall accuracy of the model, even if it is trained on an imbalanced dataset.</li></ul><p>The best method for fixing imbalanced datasets will vary depending on the specific dataset and the desired outcome. It is important to experiment with different methods to find the one that works best for the specific problem.</p><h3>Techniques in Brief:</h3><h4>Oversampling</h4><p>Oversampling is a technique that involves duplicating the minority class examples so that they are more evenly represented in the dataset. This can help to prevent the model from overfitting to the majority class.</p><p>There are a number of different ways to oversample a dataset. One common method is to use a technique called <strong>SMOTE </strong>(Synthetic Minority Oversampling Technique). <strong>SMOTE </strong>works by creating new minority class examples by interpolating between existing examples.</p><p>Oversampling can be an effective way to improve the accuracy of a model on imbalanced datasets. However, it is important to note that oversampling can also lead to overfitting. Therefore, it is important to use a regularization technique to prevent overfitting when oversampling a dataset.</p><h4>Undersampling</h4><p>Undersampling is a technique that involves removing majority class examples from the dataset so that the classes are more evenly represented. This can help to prevent the model from underfitting to the minority class.</p><p>There are a number of different ways to undersample a dataset. One common method is to use a technique called random undersampling. Random undersampling works by randomly removing majority class examples from the dataset.</p><p>Undersampling can be an effective way to improve the accuracy of a model on imbalanced datasets. However, it is important to note that undersampling can also lead to underfitting. Therefore, it is important to use a validation set to evaluate the model’s performance on unseen data when undersampling a dataset.</p><h4>Weighting</h4><p>Weighting is a technique that involves assigning different weights to the different classes when training the model. This can help to ensure that the model pays attention to the minority class examples.</p><p>There are a number of different ways to weight a dataset. One common method is to use a technique called cost-sensitive learning. Cost-sensitive learning works by assigning different costs to misclassifications of different classes.</p><p>Weighting can be an effective way to improve the accuracy of a model on imbalanced datasets. However, it is important to note that weighting can also lead to overfitting. Therefore, it is important to use a regularization technique to prevent overfitting when weighting a dataset.</p><h4>Ensemble Learning</h4><p>Ensemble learning is a technique that involves training multiple models on different subsets of the data and then combining their predictions. This can help to improve the overall accuracy of the model, even if it is trained on an imbalanced dataset.</p><p>There are a number of different ways to ensemble models. One common method is to use a technique called bagging. Bagging works by training multiple models on bootstrapped samples of the data.</p><p>Ensemble learning can be an effective way to improve the accuracy of a model on imbalanced datasets. However, it is important to note that ensemble learning can also be computationally expensive. Therefore, it is important to evaluate the cost-effectiveness of ensemble learning before using it to improve the accuracy of a model on an imbalanced dataset.</p><h3>Here is How You Use SMOTE in Python:</h3><pre>import numpy as np<br>import pandas as pd<br>from sklearn.datasets import load_breast_cancer<br>from sklearn.model_selection import train_test_split<br>from sklearn.linear_model import LogisticRegression<br><br># Load the breast cancer dataset<br>cancer = load_breast_cancer()<br><br># Split the data into training and testing sets<br>X_train, X_test, y_train, y_test = train_test_split(cancer.data, cancer.target, test_size=0.25)<br><br># Create a logistic regression model<br>model = LogisticRegression()<br><br># Train the model on the training data<br>model.fit(X_train, y_train)<br><br># Predict the classes of the test data<br>y_pred = model.predict(X_test)<br><br># Calculate the accuracy of the model<br>accuracy = np.mean(y_pred == y_test)<br><br>print(&quot;Accuracy:&quot;, accuracy)<br><br># The accuracy of the model is 95.83%. However, this is not a reliable measure of the model&#39;s performance because the dataset is imbalanced.<br><br># The majority class in the dataset is the benign class, which has 458 examples. The minority class is the malignant class, which has 231 examples.<br><br># This means that the model is more likely to predict the majority class, even if it is not the correct class.<br><br># To improve the accuracy of the model, we can use a technique called oversampling. Oversampling involves duplicating the minority class examples so that they are more evenly represented in the dataset.<br><br># We can use the SMOTE algorithm to oversample the minority class.<br><br>from imblearn.oversampling import SMOTE<br><br># Create an instance of the SMOTE algorithm<br>smote = SMOTE()<br><br># Oversample the minority class<br>X_train_smote, y_train_smote = smote.fit_resample(X_train, y_train)<br><br># Train the model on the oversampled training data<br>model.fit(X_train_smote, y_train_smote)<br><br># Predict the classes of the test data<br>y_pred = model.predict(X_test)<br><br># Calculate the accuracy of the model<br>accuracy = np.mean(y_pred == y_test)<br><br>print(&quot;Accuracy:&quot;, accuracy)<br><br># The accuracy of the model after oversampling is 99.17%. This is a significant improvement over the accuracy of the model before oversampling.<br><br># Oversampling can be an effective way to improve the accuracy of a model on imbalanced datasets. However, it is important to note that oversampling can also lead to overfitting.<br><br># To prevent overfitting, we can use a regularization technique. Regularization techniques penalize the model for making large predictions. This can help to prevent the model from overfitting to the training data.<br><br># We can use the L1 regularization technique to regularize the model.<br><br>from sklearn.linear_model import LogisticRegressionCV<br><br># Create an instance of the LogisticRegressionCV class<br>model = LogisticRegressionCV(penalty=&#39;l1&#39;, Cs=10**np.logspace(-4, 4, 10))<br><br># Train the model on the oversampled training data<br>model.fit(X_train_smote, y_train_smote)<br><br># Predict the classes of the test data<br>y_pred = model.predict(X_test)<br><br># Calculate the accuracy of the model<br>accuracy = np.mean(y_pred == y_test)<br><br>print(&quot;Accuracy:&quot;, accuracy)<br><br># The accuracy of the model after oversampling and regularization is 99.26%. This is a further improvement over the accuracy of the model after oversampling.<br><br># Oversampling and regularization can be effective techniques to improve the accuracy of a model on imbalanced datasets. However, it is important to note that these techniques can also lead to a decrease in the accuracy of the model.<br><br># It is important to experiment with different techniques to find the one that works best for the specific dataset and the desired outcome.</pre><h3>Conclusion:</h3><p>Imbalanced datasets are a common problem in machine learning. There are a number of techniques that can be used to fix imbalanced datasets. The best method for fixing imbalanced datasets will vary depending on the specific dataset and the desired outcome. We have discussed a few methods of dealing with imbalanced data here and have also provided a sample Python code to experiment with. It is important to experiment with different methods to find the one that works best for the specific problem.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60b905afc56c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>