<?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 Bello Abdullahi on Medium]]></title>
        <description><![CDATA[Stories by Bello Abdullahi on Medium]]></description>
        <link>https://medium.com/@embeeae?source=rss-3a0afc69755f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*7NzayXNNfyz_DTIn</url>
            <title>Stories by Bello Abdullahi on Medium</title>
            <link>https://medium.com/@embeeae?source=rss-3a0afc69755f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 10:09:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@embeeae/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[Why Your Machine Learning Model Might Be Cheating: Lessons From a Loan Prediction Project]]></title>
            <link>https://medium.com/@embeeae/why-your-machine-learning-model-might-be-cheating-lessons-from-a-loan-prediction-project-01554b121397?source=rss-3a0afc69755f------2</link>
            <guid isPermaLink="false">https://medium.com/p/01554b121397</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Bello Abdullahi]]></dc:creator>
            <pubDate>Fri, 05 Dec 2025 21:24:48 GMT</pubDate>
            <atom:updated>2025-12-05T21:24:48.451Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xpRypHuJVdMM8xP1PywayA.png" /></figure><p>Machine learning models fail for many reasons, but one of the most dangerous and most overlooked is <strong>data leakage</strong>.</p><p>It doesn’t show up as an error.<br> It doesn’t crash your notebook.<br> It doesn’t even cause low accuracy.</p><p>In fact, it does the opposite:<br>Your score becomes suspiciously high.</p><p>Recently, while working through a Loan Prediction notebook, I came face-to-face with this issue. Everything looked perfect. The model accuracy was impressive. The metrics were clean. But something was off.</p><p>That “something” was data leakage.</p><p>This article breaks down what I discovered, how it happens, and what you should do to prevent it, especially if you’re working with sensitive use cases like loan approvals.</p><h3>What Is Data Leakage?</h3><p>Data leakage happens when a model accidentally gains access to information it <strong>should not have during training</strong>.</p><p>This often includes:</p><ul><li>Information from the <strong>test set</strong></li><li>Information from <strong>future events</strong></li><li>Features that indirectly encode the <strong>target variable</strong></li></ul><p>When leakage occurs, the model performs extremely well on evaluation metrics but fails catastrophically in real-world deployment.</p><p>Imagine training a student for an exam but secretly giving them the marking scheme ahead of time. The student will score brilliantly in practice, but fall apart in real life. Machine learning models behave the same way.</p><h3>How Data Leakage Showed Up in the Loan Prediction Notebook</h3><p>The notebook I worked with followed a typical workflow:</p><ul><li>Data cleaning</li><li>EDA</li><li>Feature engineering</li><li>Label encoding</li><li>Train-test split</li><li>Modeling</li><li>Evaluation</li></ul><p>But buried inside those steps were leakage traps.</p><p>Below are the exact leakage patterns that surfaced.</p><h3>1. Encoding Before Splitting the Data</h3><p>A common mistake is fitting encoders (LabelEncoder, OneHotEncoder, etc.) on the entire dataset:</p><pre>le.fit(df[&#39;credit_type&#39;])</pre><p>This means the model indirectly “sees” all categories, including those only present in the test set.</p><p>What should happen instead:</p><pre>le.fit(X_train[&#39;credit_type&#39;])</pre><p>Then:</p><pre>X_test[&#39;credit_type&#39;] = X_test[&#39;credit_type&#39;].apply(...)</pre><p>This small difference completely changes the integrity of the model.</p><h3>2. Scaling the Full Dataset Before Train-Test Split</h3><p>Using StandardScaler or MinMaxScaler on the full dataset exposes the model to statistical properties of the test set:</p><pre>scaler.fit(df[numeric_cols])</pre><p>This creates a transformation that already “knows” how the test set is distributed.</p><p>The corrected workflow should look something like:</p><pre>scaler.fit(X_train[numeric_cols])<br>X_test[numeric_cols] = scaler.transform(X_test[numeric_cols])</pre><h3>3. Hidden Target Leakage in Certain Features</h3><p>The most dangerous form of leakage is when certain data fields contain future information or are highly correlated with the outcome.</p><p>In loan prediction tasks, these are common leakage features:</p><ul><li><strong>Credit bureau fields updated after loan decisions</strong></li><li><strong>Aggregated risk metrics</strong></li><li><strong>Missingness patterns</strong> that encode approval decisions</li><li><strong>Customer history fields</strong> that overlap with the target variable</li></ul><p>Without careful profiling, they sneak into the model and produce unrealistically high metrics.</p><h3>Why Data Leakage Is a Serious Problem</h3><p>When leakage is present:</p><ul><li>Your evaluation metrics become inflated</li><li>The model is overconfident</li><li>Deployment performance collapses</li><li>Business stakeholders lose trust</li><li>Decisions become unsafe (especially in finance and health)</li></ul><p>A harmless-looking notebook can quietly produce a model that is quite disastrous in production.</p><h3>How I Fixed It in the Loan Prediction Workflow</h3><p>Here is the corrected, leakage-free pipeline:</p><h3>Step 1: Split the data first</h3><pre>X_train, X_test, y_train, y_test = train_test_split(...)</pre><h3>Step 2: Fit encoders ONLY on the training data</h3><pre>le.fit(X_train[col])</pre><h3>Step 3: Handle unseen categories safely</h3><p>Apply fallback logic for new or never-seen categories.</p><h3>Step 4: Fit scalers ONLY on training data</h3><pre>scaler.fit(X_train[numeric_cols])</pre><h3>Step 5: Re-check the dataset for target leakage</h3><p>Using:</p><ul><li>Correlation analysis</li><li>Mutual information</li><li>Domain logic review</li></ul><h3>Step 6: Retrain and evaluate</h3><p>Now the accuracy reflects <em>true performance</em>, not accidental cheating.</p><h3>Key Lesson: High Accuracy Can Be a Warning, Not a Win</h3><p>Especially in tabular datasets, the easiest way for a beginner (or even an experienced practitioner) to get misled is by trusting a high model score.</p><p>In machine learning:</p><ul><li>Cleanliness &gt; Cleverness</li><li>Data handling &gt; Algorithms</li><li>Integrity &gt; Convenience</li></ul><p>A real model should succeed when exposed to <em>new, unseen</em>, real-world data, not because it inadvertently peeked at the answers during training.</p><h3>Final Thoughts</h3><p>Working through this loan prediction notebook reinforced one timeless truth:</p><p><strong>Machine learning doesn’t fail because of bad models; it fails because of bad data practices.</strong></p><p>Data leakage is subtle.<br> It’s silent.<br> It’s easy to miss.</p><p>But once you learn to spot it, you can prevent one of the most harmful failures in any ML workflow.</p><p>If you’re building real-world ML systems, especially in credit scoring, fraud detection, or healthcare, make data leakage checks part of your standard workflow.</p><p>Your future models (and your stakeholders) will thank you, and this might save a person’s life.</p><p><strong>Data leakage code</strong></p><pre># ================================================<br># IMPORTS<br># ================================================<br>import numpy as np<br>import pandas as pd<br>import matplotlib.pyplot as plt<br>import seaborn as sns<br>from matplotlib import style<br>style.use(&#39;ggplot&#39;)<br><br>import warnings<br>warnings.filterwarnings(&#39;ignore&#39;)<br><br>%matplotlib inline<br><br># ================================================<br># LOAD DATA<br># ================================================<br>df = pd.read_csv(&quot;user_dataset.csv&quot;)<br><br>print(df.shape)<br>df.head()<br>df.info()<br><br>pd.options.display.max_columns = None<br><br># ================================================<br># MISSING VALUES CHECK<br># ================================================<br>missing_df = (<br>    df.isnull()<br>      .mean()<br>      .sort_values(ascending=False)<br>      .to_frame(&quot;missing_ratio&quot;)<br>)<br><br>missing_df[&quot;missing_percentage&quot;] = (missing_df[&quot;missing_ratio&quot;] * 100).round(2)<br>missing_df<br><br>print(df.shape)<br><br># ================================================<br># COLUMN TYPES<br># ================================================<br>num_cols = df.select_dtypes(include=[&#39;int64&#39;,&#39;float64&#39;]).columns.tolist()<br>cat_cols = df.select_dtypes(include=&#39;object&#39;).columns.tolist()<br><br>print(&quot;Numeric:&quot;, num_cols)<br>print(&quot;Categorical:&quot;, cat_cols)<br><br>for col in cat_cols:<br>    print(f&quot;{col}: {df[col].nunique()} unique → {df[col].unique()[:10]}&quot;)<br><br># ================================================<br># IMPUTATION (LEAKAGE: FITTING ON FULL DATA)<br># ================================================<br>from sklearn.impute import SimpleImputer<br><br>cat_imputer = SimpleImputer(strategy=&quot;most_frequent&quot;)<br>df[cat_cols] = cat_imputer.fit_transform(df[cat_cols])   # LEAKAGE<br><br>num_imputer = SimpleImputer(strategy=&quot;mean&quot;)<br>df[num_cols] = num_imputer.fit_transform(df[num_cols])   # LEAKAGE<br><br>df.info()<br><br># ================================================<br># NUMERICAL DISTRIBUTIONS<br># ================================================<br>from scipy.stats import skew<br><br>for col in num_cols:<br>    plt.figure(figsize=(8,4))<br>    sns.histplot(df[col], kde=True, bins=30)<br>    plt.title(f&quot;Distribution of {col}&quot;)<br><br>    print(f&quot;\nColumn: {col}&quot;)<br>    print(df[col].describe().round(2))<br><br>    plt.show()<br><br># ================================================<br># CATEGORY DISTRIBUTIONS<br># ================================================<br>for col in cat_cols:<br>    plt.figure(figsize=(8,4))<br>    sns.countplot(data=df, x=col)<br>    plt.title(f&quot;Frequency of {col}&quot;)<br>    plt.xticks(rotation=45)<br>    plt.show()<br><br>df.isnull().sum()<br><br># ================================================<br># DROP UNUSED COLUMNS<br># ================================================<br>df.drop(columns=[&quot;ID&quot;, &quot;year&quot;], inplace=True, errors=&quot;ignore&quot;)<br><br># Refresh column lists<br>num_cols = df.select_dtypes(include=[&#39;int64&#39;,&#39;float64&#39;]).columns.tolist()<br>cat_cols = df.select_dtypes(include=&#39;object&#39;).columns.tolist()<br><br># ================================================<br># CATEGORY VS STATUS<br># ================================================<br>for col in cat_cols:<br>    if col == &quot;Status&quot;:<br>        continue<br><br>    print(f&quot;\n========== {col} vs Status ==========&quot;)<br>    print(pd.crosstab(df[col], df[&quot;Status&quot;], normalize=&quot;index&quot;).round(3))<br><br>    plt.figure(figsize=(8,4))<br>    sns.countplot(data=df, x=col, hue=&quot;Status&quot;)<br>    plt.title(f&quot;{col} vs Status&quot;)<br>    plt.xticks(rotation=45)<br>    plt.show()<br><br># ================================================<br># NUMERICAL STATS + CORRELATIONS<br># ================================================<br>pd.set_option(&#39;display.float_format&#39;, lambda x: f&#39;{x:,.2f}&#39;)<br><br>for col in num_cols:<br>    if col == &quot;Status&quot;:<br>        continue<br><br>    print(f&quot;\n========== {col} ==========&quot;)<br>    print(df[col].describe().to_string())<br><br>    corr = df[[col, &quot;Status&quot;]].corr().iloc[0,1]<br>    print(&quot;Correlation with Status:&quot;, round(corr, 4))<br><br>    plt.figure(figsize=(14,4))<br><br>    plt.subplot(1,2,1)<br>    sns.histplot(df[col], kde=True)<br>    plt.title(f&quot;Distribution of {col}&quot;)<br><br>    plt.subplot(1,2,2)<br>    sns.boxplot(x=df[col])<br>    plt.title(f&quot;Boxplot of {col}&quot;)<br><br>    plt.tight_layout()<br>    plt.show()<br><br># ================================================<br># HEATMAP<br># ================================================<br>plt.figure(figsize=(10,6))<br>sns.heatmap(df[num_cols].corr(), annot=True, cmap=&quot;coolwarm&quot;)<br>plt.title(&quot;Correlation Heatmap&quot;)<br>plt.show()<br><br># ================================================<br># LTV FIXING STEP<br># ================================================<br>df.loc[df[&quot;LTV&quot;] &gt; 200, &quot;LTV&quot;] = df.loc[df[&quot;LTV&quot;] &gt; 200, &quot;LTV&quot;] / 100<br><br># ================================================<br># LABEL ENCODING (LEAKAGE: FITTING ON FULL DATA)<br># ================================================<br>from sklearn.preprocessing import LabelEncoder<br><br>label_encoders = {}<br><br>for col in cat_cols:<br>    le = LabelEncoder()<br>    df[col] = le.fit_transform(df[col].astype(str))   # LEAKAGE<br>    label_encoders[col] = le<br><br># ================================================<br># PREPROCESSORS (STILL USING FULL DATA)<br># ================================================<br>from sklearn.compose import ColumnTransformer<br>from sklearn.preprocessing import StandardScaler, OneHotEncoder<br>from sklearn.impute import SimpleImputer<br>from sklearn.pipeline import Pipeline<br><br>preprocess_lr = ColumnTransformer([<br>    (&quot;num&quot;, Pipeline([<br>        (&quot;impute&quot;, SimpleImputer(strategy=&quot;mean&quot;)),<br>        (&quot;scale&quot;, StandardScaler())               # LEAKAGE<br>    ]), num_cols),<br><br>    (&quot;cat&quot;, Pipeline([<br>        (&quot;impute&quot;, SimpleImputer(strategy=&quot;most_frequent&quot;)),<br>        (&quot;encode&quot;, OneHotEncoder(handle_unknown=&quot;ignore&quot;))<br>    ]), cat_cols)<br>])<br><br>preprocess_tree = ColumnTransformer([<br>    (&quot;num&quot;, SimpleImputer(strategy=&quot;mean&quot;), num_cols),<br>    (&quot;cat&quot;, Pipeline([<br>        (&quot;impute&quot;, SimpleImputer(strategy=&quot;most_frequent&quot;)),<br>        (&quot;encode&quot;, OneHotEncoder(handle_unknown=&quot;ignore&quot;))<br>    ]), cat_cols)<br>])<br><br># ================================================<br># MODELS (TRAIN ON LEAKED DATA)<br># ================================================<br>from sklearn.linear_model import LogisticRegression<br>from sklearn.ensemble import RandomForestClassifier<br>from xgboost import XGBClassifier<br><br>lr_pipeline = Pipeline([<br>    (&quot;preprocess&quot;, preprocess_lr),<br>    (&quot;model&quot;, LogisticRegression(max_iter=300))<br>])<br><br>rf_pipeline = Pipeline([<br>    (&quot;preprocess&quot;, preprocess_tree),<br>    (&quot;model&quot;, RandomForestClassifier(n_estimators=200, random_state=42))<br>])<br><br>xgb_pipeline = Pipeline([<br>    (&quot;preprocess&quot;, preprocess_tree),<br>    (&quot;model&quot;, XGBClassifier(<br>        n_estimators=300,<br>        learning_rate=0.05,<br>        max_depth=6,<br>        random_state=42<br>    ))<br>])<br><br># ================================================<br># TRAIN–TEST SPLIT (SPLIT IS TOO LATE → LEAKAGE)<br># ================================================<br>from sklearn.model_selection import train_test_split<br><br>X = df.drop(&quot;Status&quot;, axis=1)<br>y = df[&quot;Status&quot;]<br><br>X_train, X_test, y_train, y_test = train_test_split(<br>    X, y, test_size=0.2, random_state=42, stratify=y<br>)<br><br># ================================================<br># TRAIN MODELS (AFTER LEAKED PREPROCESSING)<br># ================================================<br>lr_pipeline.fit(X_train, y_train)<br>rf_pipeline.fit(X_train, y_train)<br>xgb_pipeline.fit(X_train, y_train)<br><br># ================================================<br># EVALUATION<br># ================================================<br>from sklearn.metrics import accuracy_score, classification_report, confusion_matrix<br><br>models = {<br>    &quot;Logistic Regression&quot;: lr_pipeline,<br>    &quot;Random Forest&quot;: rf_pipeline,<br>    &quot;XGBoost&quot;: xgb_pipeline<br>}<br><br>for name, model in models.items():<br>    print(f&quot;\n===== {name} =====&quot;)<br>    preds = model.predict(X_test)<br>    print(&quot;Accuracy:&quot;, accuracy_score(y_test, preds))<br>    print(&quot;\n&quot;, classification_report(y_test, preds))<br>    print(confusion_matrix(y_test, preds))</pre><p>The result for the above was:</p><pre>Training Logistic Regression...<br> Train Acc: 0.7066<br> Test Acc:  0.7052<br><br> Training Random Forest...<br> Train Acc: 1.0000<br> Test Acc:  1.0000<br><br> Training XGBoost...<br> Train Acc: 1.0000<br> Test Acc:  1.0000</pre><p>Here’s one possible way I applied some corrections to the code; of course, there are other ways.</p><pre># ================================================<br># 0. IMPORTS<br># ================================================<br>import numpy as np<br>import pandas as pd<br>import matplotlib.pyplot as plt<br>import seaborn as sns<br><br>from sklearn.model_selection import train_test_split<br>from sklearn.pipeline import Pipeline<br>from sklearn.compose import ColumnTransformer<br>from sklearn.preprocessing import StandardScaler, OneHotEncoder<br>from sklearn.impute import SimpleImputer<br><br>from sklearn.linear_model import LogisticRegression<br>from sklearn.ensemble import RandomForestClassifier<br>from xgboost import XGBClassifier<br><br>from sklearn.metrics import accuracy_score, classification_report, confusion_matrix<br>import joblib<br><br># ================================================<br># 1. LOAD RAW DATA — NO PREPROCESSING YET<br># ================================================<br>df = pd.read_csv(&quot;your_dataset.csv&quot;)<br><br>print(df.shape)<br>df.head()<br>df.info()<br><br>num_cols   = df.select_dtypes(include=[&#39;int64&#39;,&#39;float64&#39;]).columns.tolist()<br>cat_cols   = df.select_dtypes(include=&#39;object&#39;).columns.tolist()<br><br>print(&quot;Numeric:&quot;, num_cols)<br>print(&quot;Categorical:&quot;, cat_cols)<br><br>for col in cat_cols:<br>    print(f&quot;{col}: {df[col].nunique()} unique → {df[col].unique()[:10]}&quot;)<br><br><br><br># ================================================<br># 2. EDA<br># ================================================<br>from scipy.stats import skew<br>for col in num_cols:<br>    plt.figure(figsize=(8,4))<br>    sns.histplot(df[col], kde=True, bins=30)<br>    plt.title(f&quot;Distribution of {col}&quot;)<br><br>    mean_ = df[col].mean()<br>    med_  = df[col].median()<br>    std_  = df[col].std()<br>    sk_   = skew(df[col])<br><br>    print(f&quot;\n {col}&quot;)<br>    print(f&quot;Mean     : {mean_:.2f}&quot;)<br>    print(f&quot;Median   : {med_:.2f}&quot;)<br>    print(f&quot;Std      : {std_:.2f}&quot;)<br>    print(f&quot;Skewness : {sk_:.2f}&quot;)<br><br>    plt.axvline(mean_, color=&#39;red&#39;, linestyle=&#39;--&#39;)<br>    plt.axvline(med_,  color=&#39;green&#39;, linestyle=&#39;:&#39;)<br>    plt.show()<br><br>for col in cat_cols:<br>    plt.figure(figsize=(8,4))<br>    sns.countplot(data=df, x=col)<br>    plt.title(f&quot;Frequency of {col}&quot;)<br>    plt.xticks(rotation=45)<br>    plt.show()<br><br># Remove ID and year (not useful)<br>df = df.drop(columns=[&quot;ID&quot;, &quot;year&quot;], errors=&quot;ignore&quot;)<br><br>for col in cat_cols:<br>    if col == &quot;Status&quot;: <br>        continue<br>        <br>    print(f&quot;\n========== {col} vs Status ==========&quot;)<br>    ctab = pd.crosstab(df[col], df[&quot;Status&quot;], normalize=&quot;index&quot;).round(3)<br>    print(ctab)<br><br>    plt.figure(figsize=(8,4))<br>    sns.countplot(x=col, hue=&quot;Status&quot;, data=df)<br>    plt.title(f&quot;{col} vs Status&quot;)<br>    plt.xticks(rotation=45)<br>    plt.show()<br><br>plt.figure(figsize=(10, 6))<br>sns.heatmap(df.select_dtypes(include=[&#39;float64&#39;,&#39;int64&#39;]).corr(), annot=True, cmap=&#39;coolwarm&#39;)<br>plt.title(&quot;Correlation Heatmap&quot;)<br>plt.show()<br><br>#Basic Default Distribution<br>sns.countplot(data=df, x=&quot;Status&quot;)<br>plt.title(&quot;Default Distribution&quot;)<br>plt.show()<br><br>df[&quot;Status&quot;].value_counts(normalize=True)<br><br><br>#Gender Default Rate<br>gender_default = df.groupby(&quot;Gender&quot;)[&quot;Status&quot;].value_counts(normalize=True).unstack()<br>print(gender_default)<br><br>sns.barplot(data=df, x=&quot;Gender&quot;, y=df[&quot;Status&quot;].map({&quot;Y&quot;:1,&quot;N&quot;:0}))<br>plt.title(&quot;Default Rate by Gender&quot;)<br>plt.show()<br><br>#Loan Type Default Rate<br>loan_type_default = df.groupby(&quot;Loan_Type&quot;)[&quot;Status&quot;].value_counts(normalize=True).unstack()<br>print(loan_type_default)<br><br>sns.barplot(data=df, x=&quot;Loan_Type&quot;, y=df[&quot;Status&quot;].map({&quot;Y&quot;:1,&quot;N&quot;:0}))<br>plt.title(&quot;Default Rate by Loan Type&quot;)<br>plt.xticks(rotation=45)<br>plt.show()<br><br>#Income Distribution by Default<br>sns.boxplot(data=df, x=&quot;Status&quot;, y=&quot;income&quot;)<br>plt.title(&quot;Income Distribution: Default vs Non-Default&quot;)<br>plt.show()<br><br>#Loan Amount vs Default<br>sns.boxplot(data=df, x=&quot;Status&quot;, y=&quot;loan_amount&quot;)<br>plt.title(&quot;Loan Amount vs Default Status&quot;)<br>plt.show()<br><br>#Loan Purpose Default Rate<br>purpose_default = df.groupby(&quot;Loan_Purpose&quot;)[&quot;Status&quot;].value_counts(normalize=True).unstack()<br>print(purpose_default)<br><br>sns.barplot(data=df, x=&quot;Loan_Purpose&quot;, y=df[&quot;Status&quot;].map({&quot;Y&quot;:1,&quot;N&quot;:0}))<br>plt.title(&quot;Default Rate by Loan Purpose&quot;)<br>plt.xticks(rotation=45)<br>plt.show()<br><br><br><br># Remove leaking features BEFORE splitting<br>leaking_features = [<br>    &quot;rate_of_interest&quot;,<br>    &quot;Interest_rate_spread&quot;,<br>    &quot;Upfront_charges&quot;<br>]<br>df = df.drop(columns=leaking_features, errors=&quot;ignore&quot;)<br><br># Define target &amp; features<br>X = df.drop(&quot;Status&quot;, axis=1)<br>y = df[&quot;Status&quot;]<br><br># ================================================<br># 2. TRAIN–TEST SPLIT (Split FIRST!)<br># ================================================<br>X_train, X_test, y_train, y_test = train_test_split(<br>    X, y, test_size=0.2, random_state=42, stratify=y<br>)<br><br># ================================================<br># 3. IDENTIFY COLUMN TYPES<br># ================================================<br>num_features = X_train.select_dtypes(include=[&quot;int64&quot;, &quot;float64&quot;]).columns<br>cat_features = X_train.select_dtypes(include=[&quot;object&quot;]).columns<br><br># ================================================<br># 4. BUILD SAFE PREPROCESSING PIPELINE<br># ================================================<br>numeric_transformer = Pipeline(steps=[<br>    (&quot;imputer&quot;, SimpleImputer(strategy=&quot;median&quot;)),<br>    (&quot;scaler&quot;, StandardScaler())<br>])<br><br>categorical_transformer = Pipeline(steps=[<br>    (&quot;imputer&quot;, SimpleImputer(strategy=&quot;most_frequent&quot;)),<br>    (&quot;onehot&quot;, OneHotEncoder(handle_unknown=&quot;ignore&quot;))<br>])<br><br>preprocessor = ColumnTransformer(<br>    transformers=[<br>        (&quot;num&quot;, numeric_transformer, num_features),<br>        (&quot;cat&quot;, categorical_transformer, cat_features)<br>    ]<br>)<br><br># ================================================<br># 5. BUILD MODELS WITH PIPELINES<br># ================================================<br>lr_pipeline = Pipeline([<br>    (&quot;preprocess&quot;, preprocessor),<br>    (&quot;model&quot;, LogisticRegression(max_iter=2000))<br>])<br><br>rf_pipeline = Pipeline([<br>    (&quot;preprocess&quot;, preprocessor),<br>    (&quot;model&quot;, RandomForestClassifier(n_estimators=300, random_state=42))<br>])<br><br>xgb_pipeline = Pipeline([<br>    (&quot;preprocess&quot;, preprocessor),<br>    (&quot;model&quot;, XGBClassifier(<br>        n_estimators=300,<br>        learning_rate=0.05,<br>        max_depth=6,<br>        subsample=0.8,<br>        colsample_bytree=0.8,<br>        eval_metric=&quot;logloss&quot;<br>    ))<br>])<br><br># ================================================<br># 6. TRAIN MODELS<br># ================================================<br>lr_pipeline.fit(X_train, y_train)<br>rf_pipeline.fit(X_train, y_train)<br>xgb_pipeline.fit(X_train, y_train)<br><br># ================================================<br># 7. EVALUATION<br># ================================================<br>models = {<br>    &quot;Logistic Regression&quot;: lr_pipeline,<br>    &quot;Random Forest&quot;: rf_pipeline,<br>    &quot;XGBoost&quot;: xgb_pipeline<br>}<br><br>for name, model in models.items():<br>    print(f&quot;\n=== {name} ===&quot;)<br>    preds = model.predict(X_test)<br><br>    print(&quot;Accuracy:&quot;, accuracy_score(y_test, preds))<br>    print(&quot;\nClassification Report:\n&quot;, classification_report(y_test, preds))<br>    print(&quot;Confusion Matrix:\n&quot;, confusion_matrix(y_test, preds))<br><br># ================================================<br># 8. CHOOSE BEST MODEL &amp; SAVE<br># ================================================<br>results = {<br>    name: accuracy_score(y_test, model.predict(X_test))<br>    for name, model in models.items()<br>}<br><br>best_model_name = max(results, key=results.get)<br>best_model = models[best_model_name]<br><br>print(&quot;\nBest model:&quot;, best_model_name, &quot;with accuracy:&quot;, results[best_model_name])<br><br>joblib.dump(best_model, &quot;best_model.pkl&quot;)</pre><p>The result for this is:</p><pre>MODEL TRAINING PERFORMANCE<br><br><br> Training Logistic Regression...<br> Train Acc: 0.8260<br> Test Acc:  0.8314<br><br> Training Random Forest...<br> Train Acc: 0.8898<br> Test Acc:  0.8786<br><br> Training XGBoost...<br> Train Acc: 0.9017<br> Test Acc:  0.8999</pre><p>Test it and let me know if it worked for you. Do you have better ways you’d try to avoid data leakages?</p><p>Download the dataset here: <a href="https://www.kaggle.com/datasets/yasserh/loan-default-dataset?resource=download">https://www.kaggle.com/datasets/yasserh/loan-default-dataset?resource=download</a></p><p>#dataleakage #ML #Machinelearning</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=01554b121397" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with the DHT11 Temperature and Humidity Sensor]]></title>
            <link>https://medium.com/@embeeae/getting-started-with-the-dht11-temperature-and-humidity-sensor-bde728d79e01?source=rss-3a0afc69755f------2</link>
            <guid isPermaLink="false">https://medium.com/p/bde728d79e01</guid>
            <category><![CDATA[iot]]></category>
            <dc:creator><![CDATA[Bello Abdullahi]]></dc:creator>
            <pubDate>Sat, 27 Jul 2024 20:30:25 GMT</pubDate>
            <atom:updated>2024-07-27T20:30:25.823Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Getting Started with the DHT11 Temperature and Humidity Sensor</strong></p><p><strong>Introduction</strong></p><p>The DHT11 is a popular choice for hobbyists and beginners looking to measure temperature and humidity. This low-cost sensor provides a simple way to gather environmental data for various projects. In this blog post, we&#39;ll explore how to get started with the DHT11, including its basic principles, wiring, and a simple code example using Arduino.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*U95yJzJKysIoBCr66PiiOg.jpeg" /><figcaption>DHT11</figcaption></figure><p><strong>Understanding the DHT11</strong></p><p>The DHT11 is a digital sensor that measures both temperature and humidity. It communicates with a microcontroller using a single data pin. While it&#39;s relatively inexpensive, it&#39;s important to note that its accuracy might be lower compared to more advanced sensors.</p><p>Hardware Setup<br>Required Components:</p><p>DHT11 sensor module<br>Arduino board (or compatible microcontroller)<br>Jumper wires<br>Breadboard (optional)<br>Wiring:</p><p>Connect the DHT11&#39;s VDD pin to the 5V pin on your Arduino.<br>Connect the DHT11&#39;s GND pin to the GND pin on your Arduino.<br>Connect the DHT11&#39;s DATA pin to a digital pin on your Arduino (e.g., D2).<br>Software Setup<br>Arduino Library:<br>To simplify working with the DHT11, we&#39;ll use the DHT library. You can install it through the Arduino IDE&#39;s Library Manager.</p><p>Basic Code Example:</p><p>#include &lt;DHT.h&gt;</p><p>#define DHTPIN 2 // Digital pin connected to the DHT sensor<br>#define DHTTYPE DHT11 // DHT 11</p><p>DHT dht(DHTPIN, DHTTYPE);</p><p>void setup() {<br> Serial.begin(9600);<br> dht.begin();<br>}</p><p>void loop() {<br> // Wait a few seconds between measurements.<br> delay(2000);<br> <br> // Read temperature and humidity as floats<br> float h = dht.readHumidity();<br> float t = dht.readTemperature();<br> <br> // Check if any reads failed and if so, print an error message and skip to next loop<br> if (isnan(h) || isnan(t)) {<br> Serial.println(&quot;Failed to read from DHT sensor!&quot;);<br> return;<br> }<br> <br> Serial.print(&quot;Humidity: &quot;);<br> Serial.print(h);<br> Serial.print(&quot;% &quot;);<br> Serial.print(&quot;Temperature: &quot;);<br> Serial.print(t);<br> Serial.println(&quot; *C &quot;);<br>}</p><p><strong>Code Explanation</strong><br>Include the DHT library: Imports the necessary functions for working with the DHT sensor.<br>Define pins: Specifies the digital pin connected to the DHT sensor and the sensor type.<br>Create a DHT object: Initializes a DHT object for communication.<br>Begin serial communication: Sets up serial communication for printing data.<br>Begin DHT sensor: Initializes the DHT sensor.<br>Read data: Reads humidity and temperature values from the sensor.<br>Error handling: Checks for invalid readings and prints an error message if necessary.<br>Print data: Prints the measured humidity and temperature values to the serial monitor.</p><p><strong>Additional Tips</strong><br>Accuracy: The DHT11 has limitations in accuracy. For more precise measurements, consider using sensors like DHT22 or SHT31.<br>Calibration: To improve accuracy, you might need to calibrate the sensor against a reference instrument.<br>Data Logging: Store sensor data for analysis and visualization using SD cards or data logging platforms.<br>Project Ideas: Explore various projects like weather stations, greenhouse monitoring, or indoor climate control.<br>By following these steps and experimenting with the DHT11, you can start building exciting projects that involve temperature and humidity measurements.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bde728d79e01" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Working with ODK: Creating Forms for Health Surveys]]></title>
            <link>https://medium.com/@embeeae/working-with-odk-creating-forms-for-health-surveys-7ce40061b1e9?source=rss-3a0afc69755f------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ce40061b1e9</guid>
            <dc:creator><![CDATA[Bello Abdullahi]]></dc:creator>
            <pubDate>Thu, 27 Jun 2024 20:05:00 GMT</pubDate>
            <atom:updated>2024-06-27T20:05:00.055Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Working with ODK: Creating Forms for Health Surveys</strong></p><p>Open Data Kit (ODK) is a powerful suite of tools that allows organizations to collect and manage data in challenging environments. In this blog post, I’ll share my experience creating a basic health survey form using ODK.</p><p>Getting Started After setting up ODK on my device, I began by planning out the structure of my survey. The goal was to gather general information about respondents, including some personally identifiable information (PII) and health-related data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*KtrvpPZUOM1EpmcrZbFM5g.png" /><figcaption>Source: <em>devimpactinstitute.com</em></figcaption></figure><p>Creating the Form I started with basic questions to collect demographic information:</p><ul><li>Name</li><li>Age</li><li>Gender</li><li>Contact information</li></ul><p>It’s important to note that when collecting PII, proper data protection measures must be in place to ensure respondent privacy and comply with relevant regulations.</p><p>Health-Related Questions Next, I added questions about the respondent’s health:</p><ul><li>Current health conditions</li><li>Medications</li><li>Recent symptoms</li><li>Family health history</li></ul><p>I used a combination of multiple-choice, checkbox, and open-text questions to gather this information efficiently.</p><p>Considerations and Best Practices While creating the form, I kept these key points in mind:</p><ol><li>Data sensitivity: Ensuring that sensitive health information is protected</li><li>User experience: Making the form easy to navigate and understand</li><li>Data quality: Including validation rules to improve data accuracy</li><li>Ethics: Obtaining informed consent before collecting personal information</li></ol><p><strong>Testing and Deployment</strong></p><p>Before finalizing the form, I conducted thorough testing to ensure all questions worked as intended and data was captured correctly.</p><p>ODK provides a flexible and robust platform for creating health surveys. By carefully considering question types, data sensitivity, and user experience, it’s possible to create effective forms for collecting valuable health information in various settings.</p><p><strong>Remember</strong>: <em>When working with real health data and PII, consult legal and ethics experts to ensure compliance with relevant laws and regulations.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ce40061b1e9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Leveling Up My Data Science Skills through Click-on Kaduna and Flexisaf]]></title>
            <link>https://medium.com/@embeeae/leveling-up-my-data-science-skills-through-click-on-kaduna-and-flexisaf-ca3e570c04ae?source=rss-3a0afc69755f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca3e570c04ae</guid>
            <dc:creator><![CDATA[Bello Abdullahi]]></dc:creator>
            <pubDate>Sat, 27 Apr 2024 21:19:03 GMT</pubDate>
            <atom:updated>2024-04-27T21:19:03.540Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2piVDNoRg7q5eHQ7hH7FBA.jpeg" /><figcaption>Image source: CleverTap</figcaption></figure><p>It’s been an incredible journey over the past few months as I participated in the Click-on Kaduna Data Science fellowship as well as just completed an internship with Flexisaf Edusoft company. The Click-on Kaduna was sponsored by the Bill &amp; Melinda Gates Foundation and organized by the Natview Foundation in collaboration with the Kaduna State Bureau of Statistics and the Ministry of Health, this intensive program has increased my data science skills.</p><p>The Click-on Kaduna fellowship was an immersive experience that exposed me to the latest tools and techniques in data science. From data wrangling and exploratory data analysis to machine learning modeling, I gained hands-on experience working with real-world datasets, especially with real-life health data. The curriculum covered a wide range of topics, including Python programming, data visualization, statistical analysis, powerBi, SPSS, Excel, and Data Management.</p><p>One of the most valuable lessons I learned was the importance of storytelling with data. Data science is not just about crunching numbers; it’s about extracting insights and communicating them effectively to stakeholders. I learned how to present complex data clearly and compellingly, using visualizations and narratives that resonate with diverse audiences.</p><p>Throughout the fellowship, I had the opportunity to work on several projects, tackling challenges in one of the most important areas of human endeavor which was healthcare. These projects allowed me to apply my skills to real-world problems, providing me with invaluable experience in problem-solving, critical thinking, and collaborative work.</p><p>At the same time after my in-class session with Click-on, I embarked on an internship with Flexisaf, an Ed-tech company that specializes in building human-driven solutions in Education. This internship exposed me to the cutting-edge applications of deep learning in education and beyond.</p><p>During my time at Flexisaf, I worked on exciting projects involving computer vision and natural language processing. I learned how to build and deploy deep learning models using frameworks like TensorFlow and PyTorch, and I gained insights into the ethical considerations and challenges associated with AI systems.</p><p>Looking back on this incredible journey, I am filled with gratitude for the knowledge, skills, and connections I’ve gained. The Click-on Kaduna fellowship and Flexisaf internship have not only equipped me with cutting-edge technical skills but have also taught me invaluable lessons in teamwork, communication, and problem-solving.</p><p>As I move forward in my career, I am excited to apply the expertise I’ve acquired to tackle new challenges and make a meaningful impact in the field of data science. The networks I’ve built and the opportunities that have opened up are truly invaluable, and I can’t wait to see where this journey takes me next.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca3e570c04ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stepping Stone to ML; Regression]]></title>
            <link>https://medium.com/@embeeae/stepping-stone-to-ml-regression-e977d7cae9fe?source=rss-3a0afc69755f------2</link>
            <guid isPermaLink="false">https://medium.com/p/e977d7cae9fe</guid>
            <dc:creator><![CDATA[Bello Abdullahi]]></dc:creator>
            <pubDate>Fri, 29 Mar 2024 22:13:03 GMT</pubDate>
            <atom:updated>2024-03-29T22:13:03.293Z</atom:updated>
            <content:encoded><![CDATA[<p>Introduction:</p><p>Machine learning algorithms are powerful tools that allow us to analyze and forecast outcomes based on given data sets. One such algorithm, logistic regression, is widely used for classification tasks. This blog post will explore how logistic regression can be applied to predict pumpkin types using the US-Pumpkins dataset. We’ll follow the necessary steps to build a logistic regression model and interpret the results.</p><pre><br>import pandas as pd<br>from sklearn.model_selection import train_test_split<br>from sklearn.linear_model import LogisticRegression<br>from sklearn.metrics import accuracy_score</pre><p>Understanding Logistic Regression:</p><p>Logistic regression is a supervised learning algorithm used for binary classification problems. It models the relationship between a dependent variable and one or more independent variables by estimating the probability of the dependent variable falling into a particular category. In our case, we’ll predict whether a pumpkin belongs to the “pie” or “non-pie” category.</p><p>The US-Pumpkins Dataset:</p><p>The US-Pumpkins dataset contains information about various characteristics of pumpkins, such as pumpkin variety, size, weight, and location. This dataset can be obtained from several online sources, including the United States Department of Agriculture (USDA).</p><pre><br>data = pd.read_csv(&#39;us_pumpkins.csv&#39;)</pre><p>Data Preparation:</p><p>Before building our logistic regression model, we need to prepare the data. This involves handling missing values, encoding categorical variables, and splitting the dataset into training and testing sets.</p><p>Feature Selection:</p><p>Identifying relevant features is crucial for building an effective logistic regression model. We can use techniques such as correlation analysis, feature importance, or domain knowledge to select the most influential features.</p><p>Model Training and Evaluation:</p><p>Once we have prepared the data and selected relevant features, we can proceed to train the logistic regression model. We’ll use the training set to fit the model and then evaluate its performance on the testing set. Common evaluation metrics for classification problems include accuracy, precision, recall, and F1-score.</p><p>Interpreting the Model:</p><p>Logistic regression models provide interpretable coefficients associated with each feature. These coefficients indicate the strength and direction of the relationship between the feature and the probability of a pumpkin belonging to the “pie” category.</p><p>Model Optimization:</p><p>Logistic regression models can be optimized by adjusting hyperparameters such as the regularization strength, penalty type, or solver algorithm. Techniques like cross-validation and grid search can help identify the optimal hyperparameter values.</p><p>Handling Class Imbalance:</p><p>In real-world datasets, class imbalance is a common issue where one class has significantly more samples than the other. We can address this problem by using techniques such as oversampling, undersampling, or using weighted loss functions.</p><p>Making Predictions:</p><p>Once we have trained and optimized our logistic regression model, we can use it to make predictions on new, unseen data. By providing the relevant features of a pumpkin, the model will predict the probability of it being a “pie” pumpkin.</p><p>Conclusion:</p><p>Logistic regression is a valuable tool in machine learning for binary classification tasks. In this blog post, we explored the application of logistic regression using the US-Pumpkins dataset to predict the type of pumpkins (pie or non-pie). We discussed the steps in preparing the data, selecting relevant features, training and evaluating the model, and interpreting the results. By understanding and applying logistic regression, we can gain valuable insights into pumpkin categorization and potentially extend this knowledge to other classification problems.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e977d7cae9fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Learning Journey, March.]]></title>
            <link>https://medium.com/@embeeae/my-learning-journey-march-774f47be6683?source=rss-3a0afc69755f------2</link>
            <guid isPermaLink="false">https://medium.com/p/774f47be6683</guid>
            <category><![CDATA[reflections]]></category>
            <dc:creator><![CDATA[Bello Abdullahi]]></dc:creator>
            <pubDate>Wed, 27 Mar 2024 13:04:29 GMT</pubDate>
            <atom:updated>2024-03-27T13:04:29.708Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*9HuN0h42Bqax5dawWumeWg.jpeg" /></figure><p>As I reflect on the past month, it has been a profound journey of discovery and learning particularly in the fields of artificial intelligence (AI) and machine learning (ML). From delving into the intricacies of deep learning to exploring the nuanced terrain of data ethics, and immersing myself in the realm of machine learning notebooks, each learning experience has served as a significant milestone in my quest for deeper comprehension of these transformative technologies. Join me as I contemplate the pivotal insights gained, lessons learned, and personal growth achieved during this period of exploration and learning.</p><p><strong>An Overview of Deep Learning and Neural Networks</strong></p><p>Have you ever pondered over the inner workings of neural networks? Deep learning serves as the backbone of AI innovation, akin to the <em>intellectual</em> <em>cousin</em> of machine learning, adept at handling intricate tasks such as image recognition and speech synthesis. It’s akin to imparting cognitive abilities to computers, albeit with some limitations.</p><p>From healthcare to finance, the influence of deep learning pervades diverse sectors, offering insights and prognostications akin to a modern-day oracle. Envision robots performing surgical procedures, autonomous vehicles navigating city streets, and virtual assistants addressing inquiries with precision. The scope of possibilities mirrors an endless cascade of innovation.</p><p>In light of such innovation, one thing seems to bother everyone; individuals and governments alike, the issues of data ethics. In a digital landscape where data reigns supreme, ethical considerations assume paramount importance. Data ethics epitomizes the principles of fairness, transparency, and privacy preservation. It embodies the role of a guardian, warding off the perils posed by data exploitation.</p><p>Data collection is akin to piecing together a puzzle to unveil concealed truths. However, what transpires when these puzzles harbor sensitive information or ingrained biases? It presents a conundrum. Striking a harmonious balance between data-driven insights and ethical prerogatives remains imperative. Remember, with great data comes great responsibility. We must devise means and frameworks that would ensure that data gotten to build these ML/DL models are gotten squarely and fairly but also they don’t pose possible threats to us in the future as well as they don’t become biased to a certain group of people.</p><p>Ah, the humble machine learning notebook — a canvas for coding escapades. Whether one favors Jupyter or Google Colab, these platforms serve as reliable companions in the realm of algorithms and datasets. They represent a virtual playground for coding enthusiasts. I have been reviewing other people’s models, to get a deeper sense of what I am doing, because when you start it can feel like a lot of work going on, so having other people’s work to reference is beneficial. Review as much as you can, this is highly important.</p><p>Now my advice to aspiring data sorcerers, pay heed! Mastery of machine learning notebooks necessitates diligent annotation akin to love letters to one’s future self. Maintain orderliness, liberally intersperse comments, and safeguard your endeavors (for a lost masterpiece is a grievous loss indeed). Additionally, a dash of humor can alleviate the seriousness inherent in coding pursuits (😎😎😎😎).</p><p>Exploring deep learning and data ethics this month has afforded me invaluable insights through real-world case studies. These exemplars illuminate the tangible impact of technological innovations, ranging from enhancing healthcare outcomes to fortifying cybersecurity measures.</p><p>Engaging with other people’s machine-learning notebooks has been both challenging and gratifying. The crux lies in iterative experimentation and meticulous refinement to attain optimal outcomes. Through hands-on endeavors, I’ve gleaned profound insights into model optimization and the pivotal role of data integrity in fostering accurate predictions.</p><p>Looking ahead, technologies such as reinforcement learning, natural language processing, and other upcoming frameworks promise to keep redefining the contours of AI. These advancements herald a new era of innovation across diverse domains, from finance to entertainment, presenting novel avenues for exploration and advancement.</p><p>Whilst the future of machine learning brims with promise, it is not devoid of challenges. Ethical quandaries surrounding algorithmic bias and data privacy persist as formidable obstacles warranting resolution. Nevertheless, these challenges herald opportunities for fostering transparency and accountability in the development of AI technologies.</p><p>I’ve come to realize the profound personal growth stemming from the relentless pursuit of knowledge. Each conquered concept and completed project has contributed to honing my skills and bolstering my confidence in navigating the AI and machine learning field.</p><p>Lastly, I leave you with something I picked up from Kobe Bryant, ‘Rest at the end, not a the beginning’. My Islamic teacher always says something that has equally stuck with me, ‘Rest is in paradise’. Remain curious, learn, learn, and learn some more! Stay hungry for knowledge.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=774f47be6683" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Visualization; a walk-through.]]></title>
            <link>https://medium.com/@embeeae/data-visualization-a-walk-through-8db0c69d91fb?source=rss-3a0afc69755f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8db0c69d91fb</guid>
            <dc:creator><![CDATA[Bello Abdullahi]]></dc:creator>
            <pubDate>Tue, 27 Feb 2024 21:55:45 GMT</pubDate>
            <atom:updated>2024-02-27T21:55:45.562Z</atom:updated>
            <content:encoded><![CDATA[<p>The ability to visualize complex datasets in a clear, concise, and compelling manner is invaluable. Data visualization is not just an art; it’s a science that facilitates the understanding of trends, patterns, and outliers within large datasets. This article explores the fundamentals of data visualization using Python, offering practical examples to illuminate data stories effectively.</p><h3>The Importance of Data Visualization</h3><p>Data visualization is a powerful tool for data scientists, analysts, and business professionals alike. It converts raw data into visual contexts, such as charts, graphs, and maps, making the data more accessible and easier to understand. Effective visualizations can highlight new insights, support decision-making, and communicate findings to both technical and non-technical audiences.</p><h3>Python’s Visualization Libraries</h3><p>Python offers several libraries for creating visually appealing and informative data visualizations. The most popular among these include Matplotlib, Seaborn, and Plotly:</p><ul><li>Matplotlib: A low-level graph plotting library that offers extensive control over elements.</li><li>Seaborn: Built on top of Matplotlib, it provides a high-level interface for drawing attractive and informative statistical graphics.</li><li>Plotly: Offers both online and offline plotting. Plotly can create interactive plots that are highly customizable and suitable for web applications.</li></ul><h3>Getting Started</h3><p>Before diving into the examples, ensure you have the necessary libraries installed:</p><pre>pip install matplotlib seaborn plotly</pre><p>To demonstrate the power of data visualization in uncovering insights from data, we will use a dataset titled birds.csv. Our goal is to create a compelling narrative by visualizing this dataset with Python. We will explore the dataset to understand its structure, then proceed to visualize it using Python&#39;s popular libraries: Matplotlib and Seaborn.</p><h3>Step 1: Understanding the Dataset</h3><p>First, let’s load the dataset using pandas to understand its structure and contents.</p><pre>import pandas as pd<br><br># Load the dataset<br>df = pd.read_csv(&#39;birds.csv&#39;)<br><br># Display the first few rows of the dataframe<br>print(df.head())</pre><pre>Name          ScientificName  \<br>0  Black-bellied whistling-duck  Dendrocygna autumnalis   <br>1        Fulvous whistling-duck     Dendrocygna bicolor   <br>2                    Snow goose      Anser caerulescens   <br>3                  Ross&#39;s goose            Anser rossii   <br>4   Greater white-fronted goose         Anser albifrons   <br><br>                Category         Order    Family        Genus  \<br>0  Ducks/Geese/Waterfowl  Anseriformes  Anatidae  Dendrocygna   <br>1  Ducks/Geese/Waterfowl  Anseriformes  Anatidae  Dendrocygna   <br>2  Ducks/Geese/Waterfowl  Anseriformes  Anatidae        Anser   <br>3  Ducks/Geese/Waterfowl  Anseriformes  Anatidae        Anser   <br>4  Ducks/Geese/Waterfowl  Anseriformes  Anatidae        Anser   <br><br>  ConservationStatus  MinLength  MaxLength  MinBodyMass  MaxBodyMass  \<br>0                 LC       47.0       56.0        652.0       1020.0   <br>1                 LC       45.0       53.0        712.0       1050.0   <br>2                 LC       64.0       79.0       2050.0       4050.0   <br>3                 LC       57.3       64.0       1066.0       1567.0   <br>4                 LC       64.0       81.0       1930.0       3310.0   <br><br>   MinWingspan  MaxWingspan  <br>0         76.0         94.0  <br>1         85.0         93.0  <br>2        135.0        165.0  <br>3        113.0        116.0  <br>4        130.0        165.0</pre><h3>Step 2: Initial Data Exploration</h3><p>Before visualizing, we&#39;ll perform a brief exploration to identify potential patterns, anomalies, or points of interest that could be valuable for our visual story.</p><pre># Basic statistics<br>print(df.describe())<br><br># Check for missing values<br>print(df.isnull().sum())<br><br># Understand data types and column distribution<br>print(df.info())</pre><pre>MinLength   MaxLength  MinBodyMass   MaxBodyMass  MinWingspan  \<br>count  443.000000  443.000000   443.000000    443.000000   443.000000   <br>mean    28.536682   35.441986   327.938262    667.009752    58.557901   <br>std     20.319887   27.539772   779.680106   1655.682564   104.602369   <br>min      7.000000    8.900000     2.000000      3.000000     8.000000   <br>25%     13.750000   16.000000    18.000000     28.000000    23.000000   <br>50%     20.500000   25.000000    55.000000     89.000000    38.000000   <br>75%     39.000000   46.000000   332.000000    593.000000    72.750000   <br>max    138.000000  180.000000  9200.000000  14300.000000  1800.000000   <br><br>       MaxWingspan  <br>count   443.000000  <br>mean     67.524492  <br>std     126.673177  <br>min      10.600000  <br>25%      25.000000  <br>50%      42.000000  <br>75%      83.000000  <br>max    2300.000000  <br>Name                  0<br>ScientificName        0<br>Category              0<br>Order                 0<br>Family                0<br>Genus                 0<br>ConservationStatus    0<br>MinLength             0<br>MaxLength             0<br>MinBodyMass           0<br>MaxBodyMass           0<br>MinWingspan           0<br>MaxWingspan           0<br>dtype: int64<br>&lt;class &#39;pandas.core.frame.DataFrame&#39;&gt;<br>RangeIndex: 443 entries, 0 to 442<br>Data columns (total 13 columns):<br> #   Column              Non-Null Count  Dtype  <br>---  ------              --------------  -----  <br> 0   Name                443 non-null    object <br> 1   ScientificName      443 non-null    object <br> 2   Category            443 non-null    object <br> 3   Order               443 non-null    object <br> 4   Family              443 non-null    object <br> 5   Genus               443 non-null    object <br> 6   ConservationStatus  443 non-null    object <br> 7   MinLength           443 non-null    float64<br> 8   MaxLength           443 non-null    float64<br> 9   MinBodyMass         443 non-null    float64<br> 10  MaxBodyMass         443 non-null    float64<br> 11  MinWingspan         443 non-null    float64<br> 12  MaxWingspan         443 non-null    float64<br>dtypes: float64(6), object(7)<br>memory usage: 45.1+ KB<br>None</pre><p>Based on the initial exploration, we can decide on the types of visualizations that might be most effective. For instance, if the dataset includes temporal data, line charts could illustrate trends over time. If it contains categorical data, bar charts or pie charts might be more appropriate to show distributions.</p><h3>Step 3: Visualization with Matplotlib and Seaborn</h3><p>Assuming our dataset contains information about different bird species, their population numbers, and conservation statuses, we can craft visualizations to convey this information effectively.</p><h3>Example 1: Conservation Status Distribution</h3><p>First, we’ll visualize the distribution of the conservation status of these bird species.</p><pre># Plotting Conservation Status Distribution<br>status_counts = df[&#39;ConservationStatus&#39;].value_counts()<br>plt.figure(figsize=(10, 6))<br>status_counts.plot(kind=&#39;bar&#39;)<br>plt.title(&#39;Conservation Status of Bird Species&#39;)<br>plt.xlabel(&#39;Conservation Status&#39;)<br>plt.ylabel(&#39;Number of Species&#39;)<br>plt.xticks(rotation=45)<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*htSVmoR42tCJvRo5YX8lMA.png" /></figure><h3>Example 2: Body Mass Distribution by Conservation Status</h3><p>Next, we’ll explore how the body mass of these birds varies with their conservation status, which can provide insights into whether certain sizes of birds are more at risk.</p><pre># Assuming MinBodyMass and MaxBodyMass represent the range of body mass for each species<br>df[&#39;AverageBodyMass&#39;] = (df[&#39;MinBodyMass&#39;] + df[&#39;MaxBodyMass&#39;]) / 2</pre><pre># Plotting Body Mass Distribution by Conservation Status<br>plt.figure(figsize=(12, 8))<br>sns.boxplot(x=&#39;ConservationStatus&#39;, y=&#39;AverageBodyMass&#39;, data=df)<br>plt.title(&#39;Body Mass Distribution by Conservation Status&#39;)<br>plt.xlabel(&#39;Conservation Status&#39;)<br>plt.ylabel(&#39;Average Body Mass (g)&#39;)<br>plt.xticks(rotation=45)<br>plt.yscale(&#39;log&#39;)  # Using a log scale for better visualization of wide ranges<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9qkRdz-gy3oLJ_7lCS9nlA.png" /></figure><h3>Conclusion</h3><p>Data visualization is a powerful storytelling tool that allows us to communicate complex datasets in an intuitive and impactful way. By applying Python&#39;s Matplotlib and Seaborn libraries, we can transform raw data into meaningful stories that capture the audience&#39;s attention and convey key insights at a glance.</p><p>Remember, the key to effective data visualization lies not only in choosing the right type of chart but also in crafting a narrative that guides the viewer through the data coherently and engagingly. Whether you are a data scientist, a business analyst, or a researcher, mastering the art of data visualization is crucial for turning data into actionable insights.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8db0c69d91fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Preparation: A Gateway to Insightful Analysis]]></title>
            <link>https://medium.com/@embeeae/data-preparation-a-gateway-to-insightful-analysis-31eeced38b39?source=rss-3a0afc69755f------2</link>
            <guid isPermaLink="false">https://medium.com/p/31eeced38b39</guid>
            <dc:creator><![CDATA[Bello Abdullahi]]></dc:creator>
            <pubDate>Tue, 27 Feb 2024 21:15:55 GMT</pubDate>
            <atom:updated>2024-02-27T21:15:55.707Z</atom:updated>
            <content:encoded><![CDATA[<p>Data preparation is an essential step in the data analysis process, often consuming the most time but also significantly impacting the quality of insights derived. It involves cleaning, transforming, and organizing raw data into a structured format suitable for analysis. In this blog post, we’ll dive into the intricacies of data preparation, providing practical code examples using Python, to help you streamline this critical phase of your data science projects.</p><h3>Understanding Data Preparation</h3><p>Data preparation is the process of converting raw data into a clean dataset. Before any meaningful analysis can be performed, data must be:</p><ul><li>Cleaned: Removing or correcting inaccurate, incomplete, or irrelevant data.</li><li>Transformed: Changing the data’s format or structure to make it more suitable for analysis.</li><li>Organized: Structuring the data in a way that aligns with the analysis objectives.</li></ul><p>The goal is to ensure the data is accurate, complete, and ready for analysis, enabling data scientists and analysts to uncover reliable insights.</p><h3>Tools for Data Preparation</h3><p>Python, with its rich ecosystem of libraries such as Pandas, NumPy, and SciPy, is a powerful tool for data preparation. Pandas, in particular, are widely used for their data manipulation capabilities.</p><h3>Step 1: Setting Up Your Environment</h3><p>Ensure you have Python and Pandas installed. Install Pandas using pip if you haven’t already:</p><pre>pip install pandas</pre><h3>Step 2: Loading Your Data</h3><p>First, load your data into a Pandas DataFrame. DataFrames are two-dimensional, size-mutable, and potentially heterogeneous tabular data structures with labeled axes.</p><pre>import pandas as pd</pre><pre># Load a CSV file<br>df = pd.read_csv(&#39;path/to/your/data.csv&#39;)</pre><pre># Load an Excel file<br># df = pd.read_excel(&#39;path/to/your/data.xlsx&#39;)</pre><h3>Step 3: Cleaning the Data</h3><p>Data cleaning might involve handling missing values, removing duplicates, or correcting errors.</p><h4>Handling Missing Values</h4><pre># Drop rows with any missing values<br>df_clean = df.dropna()</pre><pre># Fill missing values with a placeholder or mean of the column<br>df_filled = df.fillna(0)  # Or df.fillna(df.mean())</pre><h4>Removing Duplicates</h4><pre>df_unique = df.drop_duplicates()</pre><h4>Correcting Errors</h4><p>This could involve applying functions to correct data formats or values.</p><pre># Correcting a typo in a column<br>df[&#39;Column&#39;] = df[&#39;Column&#39;].replace(&#39;incorrect_value&#39;, &#39;correct_value&#39;)</pre><h3>Step 4: Transforming the Data</h3><p>Transformation can involve normalizing data, converting data types, or creating new variables.</p><h4>Normalizing Data</h4><pre># Example: Min-Max normalization<br>df[&#39;Normalized&#39;] = (df[&#39;Column&#39;] - df[&#39;Column&#39;].min()) / (df[&#39;Column&#39;].max() - df[&#39;Column&#39;].min())</pre><h4>Converting Data Types</h4><pre>df[&#39;NumericColumn&#39;] = pd.to_numeric(df[&#39;NumericColumn&#39;], errors=&#39;coerce&#39;)</pre><h4>Creating New Variables</h4><pre># Example: Creating a categorical variable from a numeric variable<br>df[&#39;Category&#39;] = pd.cut(df[&#39;NumericColumn&#39;], bins=[0,10,20,30], labels=[&quot;Low&quot;, &quot;Medium&quot;, &quot;High&quot;])</pre><h3>Step 5: Organizing the Data</h3><p>Organizing your data effectively can make analysis more straightforward.</p><h4>Sorting</h4><pre>df_sorted = df.sort_values(by=&#39;Column&#39;)</pre><h4>Grouping</h4><pre>df_grouped = df.groupby(&#39;Category&#39;).mean()</pre><h3>Conclusion</h3><p>Data preparation is a critical yet time-consuming part of the data analysis process. By leveraging Python and its libraries, specifically Pandas, you can streamline the data preparation workflow, making it easier to clean, transform, and organize your data. The examples provided here are just the beginning. As you become more familiar with these tools, you’ll find that your ability to manipulate data efficiently will greatly enhance the quality of your insights.</p><p>Remember, the cleaner and more structured your data, the more accurate and insightful your analysis will be. Happy data prepping!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31eeced38b39" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Manipulation with Pandas]]></title>
            <link>https://medium.com/@embeeae/data-manipulation-with-pandas-e92fb3fa0679?source=rss-3a0afc69755f------2</link>
            <guid isPermaLink="false">https://medium.com/p/e92fb3fa0679</guid>
            <dc:creator><![CDATA[Bello Abdullahi]]></dc:creator>
            <pubDate>Tue, 27 Feb 2024 21:11:59 GMT</pubDate>
            <atom:updated>2024-02-27T21:11:59.659Z</atom:updated>
            <content:encoded><![CDATA[<p>In this ever-changing world of data science and analysis, the ability to manipulate and analyze data efficiently is crucial. Python’s Pandas library stands out as a powerful tool for these tasks, offering extensive capabilities for data manipulation and analysis. This guide will walk you through the fundamentals of Pandas, accompanied by code snippets to help you get a practical understanding of how to use it effectively.</p><h3>Introduction to Pandas</h3><p>Pandas is an open-source data analysis and manipulation tool built on top of the Python programming language. It provides fast, flexible, and expressive data structures designed to make working with “relational” or “labeled” data both easy and intuitive. Pandas is perfect for a wide range of data operations including but not limited to cleaning, transforming, merging, reshaping, and aggregation.</p><p>The two primary data structures of pandas are:</p><ol><li>DataFrame: A two-dimensional, size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns).</li><li>Series: A one-dimensional labeled array capable of holding any data type.</li></ol><h3>Getting Started with Pandas</h3><p>Before diving into the code, ensure you have Pandas installed in your Python environment. You can install Pandas using pip:</p><pre>!pip install pandas</pre><h3>Importing Pandas</h3><p>To start using Pandas, you first need to import it into your Python script. It’s common practice to import Pandas with the alias pd:</p><pre>import pandas as pd</pre><h3>Creating a DataFrame</h3><p>Let’s begin by creating a simple DataFrame. DataFrames can be created from various data sources like lists, dictionaries, or even external data files (CSV, Excel).</p><pre>data = {<br>    &#39;Name&#39;: [&#39;John&#39;, &#39;Anna&#39;, &#39;Peter&#39;, &#39;Linda&#39;],<br>    &#39;Age&#39;: [28, 34, 29, 32],<br>    &#39;City&#39;: [&#39;New York&#39;, &#39;Paris&#39;, &#39;Berlin&#39;, &#39;London&#39;]<br>}<br>df = pd.DataFrame(data)<br>print(df)</pre><p>This code snippet creates a DataFrame from a dictionary where keys become column labels and values are the data entries.</p><h3>Reading Data Files</h3><p>One of Pandas’ most powerful features is its ability to quickly read data from files. Here’s how you can read a CSV file:</p><pre>df = pd.read_csv(&#39;path/to/your/file.csv&#39;)</pre><p>Similarly, to read an Excel file, you can use:</p><pre>df = pd.read_excel(&#39;path/to/your/file.xlsx&#39;)</pre><h3>Data Exploration</h3><p>Once you have your data loaded into a DataFrame, Pandas provides several functions to explore your dataset. Here are a few essential ones:</p><ul><li>head(): View the first few rows of the data frame.</li><li>info(): Get a concise summary of the data frame.</li><li>describe(): Generate descriptive statistics.</li></ul><pre># Display the first 5 rows<br>print(df.head())</pre><pre># Summary of the DataFrame<br>print(df.info())</pre><pre># Descriptive statistics<br>print(df.describe())</pre><h3>Selecting and Filtering Data</h3><p>Pandas allow for selecting specific columns or filtering rows based on conditions.</p><pre># Select a single column<br>ages = df[&#39;Age&#39;]</pre><pre># Select multiple columns<br>subset = df[[&#39;Name&#39;, &#39;Age&#39;]]</pre><pre># Filter rows where Age &gt; 30<br>older_than_30 = df[df[&#39;Age&#39;] &gt; 30]</pre><h3>Modifying Data</h3><p>You can also add new columns, modify existing ones, or apply functions to data.</p><pre># Add a new column<br>df[&#39;Senior&#39;] = df[&#39;Age&#39;] &gt; 60</pre><pre># Modify a column<br>df[&#39;Age&#39;] = df[&#39;Age&#39;] + 1</pre><pre># Apply a function to each row<br>df[&#39;Name Length&#39;] = df[&#39;Name&#39;].apply(len)</pre><h3>Grouping and Aggregating Data</h3><p>Pandas excels at grouping and aggregating data, making it easy to perform complex data analysis tasks.</p><pre># Group by city and calculate mean age<br>mean_age_by_city = df.groupby(&#39;City&#39;)[&#39;Age&#39;].mean()<br>print(mean_age_by_city)</pre><h3>Merging and Joining DataFrames</h3><p>Combining data from multiple sources is a common task, and Pandas provides several methods to merge and join DataFrames.</p><pre>df1 = pd.DataFrame({&#39;Key&#39;: [&#39;A&#39;, &#39;B&#39;, &#39;C&#39;], &#39;Value&#39;: [1, 2, 3]})<br>df2 = pd.DataFrame({&#39;Key&#39;: [&#39;B&#39;, &#39;C&#39;, &#39;D&#39;], &#39;Value&#39;: [4, 5, 6]})</pre><pre># Merge df1 and df2 on the &#39;Key&#39; column<br>merged_df = pd.merge(df1, df2, on=&#39;Key&#39;</pre><h3>Conclusion</h3><p>Pandas is an indispensable tool for data manipulation and analysis in Python. This guide has covered the basics, from creating and reading DataFrames to selecting, filtering, and modifying data. We also touched on more advanced topics like grouping, aggregating, and merging data. With these fundamentals, you’re well on your way to mastering data analysis with Pandas.</p><p>Remember, the key to proficiency in Pandas (or any programming skill) is practice. Try applying these concepts to your data projects, and explore the Pandas documentation for more advanced features and techniques. Happy data wrangling!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e92fb3fa0679" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to NumPy]]></title>
            <link>https://medium.com/@embeeae/introduction-to-numpy-55ce52971691?source=rss-3a0afc69755f------2</link>
            <guid isPermaLink="false">https://medium.com/p/55ce52971691</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[numpy]]></category>
            <dc:creator><![CDATA[Bello Abdullahi]]></dc:creator>
            <pubDate>Sun, 11 Feb 2024 22:08:59 GMT</pubDate>
            <atom:updated>2024-02-11T22:08:59.383Z</atom:updated>
            <content:encoded><![CDATA[<p>NumPy, short for Numerical Python, is a powerful library in Python used for numerical computations. In this blog, I will explore some basic NumPy functions and commands, so, let’s dive in!</p><ol><li>Importing NumPy and Checking Version:</li></ol><pre>import numpy as np<br><br># Check NumPy version and configuration<br>print(np.__version__)<br>print(np.show_config())</pre><p>This code imports the NumPy library into the Python environment and assigns it an alias ‘np’. Then, it prints out the version of NumPy installed and displays the configuration details such as compilation options and library paths.</p><p>2. Creating a Null Vector of Size 10</p><pre>null_vector = np.zeros(10)<br>print(null_vector)</pre><p>Here, a null vector of size 10 is created using the np.zeros() function from NumPy, which generates an array filled with zeros. The resulting null vector is then printed.</p><p>3. Finding the Memory Size of an Array</p><pre>array_size = np.zeros(10)<br>print(array_size.size * array_size.itemsize)</pre><p>This code calculates the memory size of the array array_size by multiplying the number of elements in the array (array_size.size) with the size (in bytes) of each element (array_size.itemsize). Since all elements are zeros, the memory size represents the overhead of storing the array structure.</p><p>4. Creating a Null Vector with the Fifth Value as 1</p><pre>null_vector = np.zeros(10)<br>null_vector[4] = 1<br>print(null_vector)</pre><p>This code creates a null vector of size 10 but sets the fifth element (index 4, since indexing starts from 0) to 1. It then prints the modified null vector.</p><p>5. Creating a Vector Ranging from 10 to 49</p><pre>vector_range = np.arange(10, 50)<br>print(vector_range)</pre><p>In this code, np.arange() function from NumPy creates an array of evenly spaced values within a specified range. The function generates values from the starting point (inclusive) to the ending point (exclusive), with a default step size of 1. Here, np.arange(10, 50) generates a sequence of integers starting from 10 and ending at 49 (excluding 50), resulting in an array containing values from 10 to 49. Finally, the array vector_range is printed.</p><p>6. Reversing a Vector</p><pre>vector = np.arange(10)<br>reversed_vector = vector[::-1]<br>print(reversed_vector)</pre><p>In this code, np.arange(10) generates an array of integers from 0 to 9. Then, the slicing notation [::-1] is used on vector to reverse the order of elements. This notation creates a new array with a step size of -1, effectively reversing the original array. Finally, the reversed vector reversed_vector is printed, displaying the elements of the original vector in reverse order.</p><p>7. Creating a 3x3 Matrix with Values Ranging from 0 to 8</p><pre>matrix = np.arange(9).reshape(3, 3)<br>print(matrix)</pre><p>In this code, np.arange(9) generates a one-dimensional array containing integers from 0 to 8. Then, the reshape(3, 3) function is applied to the array, which reshapes it into a 3x3 matrix. Each row of the matrix contains three consecutive elements from the original array. Finally, the resulting matrix matrix is printed, displaying the values ranging from 0 to 8 arranged in a 3x3 grid.</p><p>8. Finding Indices of Non-Zero Elements</p><pre>array = np.array([1, 2, 0, 0, 4, 0])<br>non_zero_indices = np.nonzero(array)<br>print(non_zero_indices)</pre><p>In this code, np.array([1, 2, 0, 0, 4, 0]) create a NumPy array containing the specified elements. The np.nonzero() function is then applied to the array, which returns the indices of elements that are non-zero. The resulting non_zero_indices array contains the indices of non-zero elements from the original array. Finally, the array of non-zero indices is printed.</p><p>9. Creating a 3x3 Identity Matrix</p><pre>identity_matrix = np.eye(3)<br>print(identity_matrix)</pre><p>In this code, np.eye(3) generates a 3x3 identity matrix, which is a square matrix where all elements on the diagonal are 1, and all other elements are 0. The np.eye() function creates an identity matrix with the specified number of rows and columns, in this case, 3. Finally, the resulting identity matrix identity_matrix is printed, showing a 3x3 matrix with 1s on the diagonal and 0s elsewhere.</p><p>10. Creating a 3x3x3 Array with Random Values</p><pre>random_array = np.random.random((3, 3, 3))<br>print(random_array)</pre><p>In this code, np.random.random((3, 3, 3)) generates a 3x3x3 array filled with random floating-point values in the range [0.0, 1.0). The np.random.random() function creates an array of the specified shape (in this case, 3x3x3) and fills it with random values sampled from a uniform distribution over the interval [0.0, 1.0). Finally, the resulting random array random_array is printed, displaying the 3x3x3 array with random values.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55ce52971691" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>