<?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 Maryam Meshref  on Medium]]></title>
        <description><![CDATA[Stories by Maryam Meshref  on Medium]]></description>
        <link>https://medium.com/@maryam.meshref.75?source=rss-d4aa6cd3974e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*DkEbsCD62EOhm3WQ</url>
            <title>Stories by Maryam Meshref  on Medium</title>
            <link>https://medium.com/@maryam.meshref.75?source=rss-d4aa6cd3974e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 09:29:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@maryam.meshref.75/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[linear regression]]></title>
            <link>https://medium.com/@maryam.meshref.75/linear-regression-e86889804f75?source=rss-d4aa6cd3974e------2</link>
            <guid isPermaLink="false">https://medium.com/p/e86889804f75</guid>
            <dc:creator><![CDATA[Maryam Meshref ]]></dc:creator>
            <pubDate>Tue, 17 Nov 2026 08:33:57 GMT</pubDate>
            <atom:updated>2026-11-17T08:33:57.875Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>My First Linear Regression in Python</strong></p><p><em>A beginner-friendly, step-by-step guide using pandas, NumPy, and statsmodels</em></p><p>Linear Regression is one of the most useful starting points in machine learning and data analysis. In this guide, we will build a simple regression model that uses a student’s SAT score to predict their GPA. We will explain every line of code, understand the most common beginner mistakes, and learn how to read the model output.</p><p><strong>The goal is not to memorize code. The goal is to understand what each line does, what kind of data it expects, and why the steps are necessary.</strong></p><h3>1. What is Linear Regression?</h3><p>Linear Regression is a statistical method used to describe the relationship between a dependent variable and one or more independent variables. It can also be used to make predictions.</p><p>For example, suppose we want to investigate whether a student’s SAT score is related to their GPA. We can use SAT as the input and GPA as the value we want to predict.</p><p><strong>Y = b₀ + b₁X</strong></p><p>· Y: the dependent variable — the value we want to predict (GPA).</p><p>· X: the independent variable — the input used to make the prediction (SAT).</p><p>· b₀: the intercept — the predicted value of Y when X equals zero.</p><p>· b₁: the slope — how much the predicted Y changes when X increases by one unit.</p><p>In a simple linear regression model, there is one independent variable. If we use two or more independent variables, we have multiple linear regression.</p><h3>2. Meet the Dataset</h3><p>Imagine that our pandas DataFrame is called data and contains these columns: SAT, Rand 1,2,3, and GPA. The first two columns could be used as predictors; GPA is the outcome we want to predict in this example.</p><p>import pandas as pd<br>import statsmodels.api as sm</p><p># Example: load your dataset<br># data = pd.read_csv(‘your_file.csv’)</p><p>print(data.head())<br>print(data.dtypes)</p><p>data.head() displays the first five rows by default. It helps us inspect the values. data.dtypes shows the data type of every column.</p><h3>What do the data types mean?</h3><p>· int64: whole-number values, such as 1200 or 3.</p><p>· float64: decimal values, such as 3.75.</p><p>· object or string: often text values, although an object column can also contain mixed types.</p><p>In our example, the output showed SAT and Rand 1,2,3 as int64, and GPA as float64. That tells us the columns in data are already numeric.</p><h3>3. Series vs DataFrame: One Bracket or Two?</h3><p>This distinction is important in pandas. Selecting one column with one pair of square brackets returns a Series. Selecting it with two pairs returns a DataFrame.</p><p>sat_series = data[‘SAT’] # Series (one-dimensional)<br>sat_frame = data[[‘SAT’]] # DataFrame (two-dimensional)</p><p>two_columns = data[[‘SAT’, ‘Rand 1,2,3’]]</p><p>Both sat_series and sat_frame contain the SAT values. The difference is their structure. statsmodels can work with either in many cases, but understanding the difference helps avoid shape and selection mistakes.</p><p><strong>Code</strong></p><p><strong>What it selects</strong></p><p><strong>Result type</strong></p><p>data[‘SAT’]</p><p>One column</p><p>Series</p><p>data[[‘SAT’]]</p><p>One column</p><p>DataFrame</p><p>data[[‘SAT’, ‘GPA’]]</p><p>Two columns</p><p>DataFrame</p><h3>4. The Mistake That Caused UFuncTypeError</h3><p>The error in our troubleshooting session was:</p><p>UFuncTypeError: ufunc ‘maximum’ did not contain a loop with signature matching types (dtype(‘&lt;U10’), dtype(‘&lt;U10’))</p><p>The important clue is dtype(‘&lt;U10’). It indicates that NumPy was handling Unicode text values (strings), not numeric values. statsmodels tried to inspect the values while adding a constant, but it could not perform a numeric operation on text.</p><h3>The key mix-up</h3><p>x1 = [[‘SAT’, ‘Rand 1,2,3’]]</p><p>This creates a Python list containing the literal text ‘SAT’ and ‘Rand 1,2,3’. It does not select the SAT values from the DataFrame. The column names are labels; they are not the actual observations.</p><p>To select the actual data, we must select the columns from the DataFrame:</p><p>x1 = data[[‘SAT’]]</p><p><strong>Remember: data[[‘SAT’]] means “get the SAT column from the DataFrame named data.” [[‘SAT’]] by itself is only a list containing text.</strong></p><h3>Why did data.dtypes look correct?</h3><p>Because data and x1 are separate variables. data can contain numeric columns while x1 still contains an incorrectly created list of strings. Always inspect the variable you are actually passing into the model.</p><p>print(type(x1))<br>print(x1)<br>print(getattr(x1, ‘dtype’, ‘No dtype’))</p><p>A pandas DataFrame has .dtypes (plural), while a pandas Series or NumPy array has .dtype (singular). A plain Python list does not have a .dtype attribute, which is why getattr(…, ‘No dtype’) displayed ‘No dtype’.</p><h3>5. Build a Simple Linear Regression Model</h3><h3>Step 1 — Choose X and Y</h3><p>x1 = data[[‘SAT’]]<br>y = data[‘GPA’]</p><p>x1 contains the independent variable (SAT). y contains the dependent variable (GPA). Notice that we use double brackets for x1 so it remains a two-dimensional DataFrame, and single brackets for y so it is a Series.</p><h3>Step 2 — Convert the data type if necessary</h3><p>x1 = x1.astype(float)<br>y = y.astype(float)</p><p>astype(float) converts the selected values to floating-point numbers. In our example, SAT was already int64 and GPA was already float64, so this conversion was not strictly necessary. It is included to make the numeric type explicit. If a column contains non-numeric text, astype(float) may fail; inspect and clean the data first.</p><h3>Step 3 — Add the constant</h3><p>x = sm.add_constant(x1)</p><p>statsmodels does not automatically add the intercept column in this workflow. add_constant() adds a column of 1s. This allows the model to estimate b₀ in the equation Y = b₀ + b₁X.</p><h3>Step 4 — Fit the model</h3><p>results = sm.OLS(y, x).fit()</p><p>OLS stands for Ordinary Least Squares. It estimates the coefficients by finding the line that minimizes the sum of squared differences between the actual GPA values and the values predicted by the line. The .fit() method performs the estimation and stores the fitted results.</p><h3>Step 5 — Display the summary</h3><p>results.summary()</p><p>This displays a report containing the estimated coefficients, model fit statistics, and statistical tests.</p><h3>6. The Complete Code</h3><p>Here is the full workflow in one place. Run it after loading your dataset into a DataFrame named data.</p><p>import pandas as pd<br>import statsmodels.api as sm</p><p># Inspect the dataset<br>print(data.head())<br>print(data.dtypes)</p><p># Select the independent and dependent variables<br>x1 = data[[‘SAT’]]<br>y = data[‘GPA’]</p><p># Make the numeric types explicit (optional if already numeric)<br>x1 = x1.astype(float)<br>y = y.astype(float)</p><p># Add the intercept column<br>x = sm.add_constant(x1)</p><p># Fit the Ordinary Least Squares model<br>results = sm.OLS(y, x).fit()</p><p># Display the regression report<br>print(results.summary())</p><h3>7. How to Read results.summary()</h3><h3>The coefficients</h3><p>Look at the coef column. The row named const is the estimated intercept (b₀). The row named SAT is the estimated slope (b₁). Your fitted equation will have this form:</p><p><strong>Predicted GPA = intercept + (SAT coefficient × SAT)</strong></p><p>Use the actual coefficient values shown in your own output. Do not copy example values from another dataset.</p><h3>R-squared</h3><p>R-squared describes how much of the variation in the dependent variable is explained by the model, within the dataset used to fit it. For example, an R-squared of 0.70 means the model explains about 70% of the variation in GPA in that sample. It does not mean that 70% of predictions are correct.</p><h3>P-value</h3><p>The P&gt;|t| column reports a p-value for each coefficient. A small p-value (often compared with 0.05) is evidence against the null hypothesis that the coefficient is zero, under the model’s assumptions. Statistical significance does not automatically mean the relationship is large, useful, or causal.</p><h3>Other useful fields</h3><p>· Adj. R-squared: adjusts R-squared for the number of predictors.</p><p>· F-statistic and Prob (F-statistic): assess the model as a whole.</p><p>· Confidence interval: a range of plausible values for a coefficient under the model assumptions.</p><p>· No. Observations: the number of observations used by the model.</p><h3>8. What if I Want to Use Two Predictors?</h3><p>If the task asks you to use both SAT and Rand 1,2,3 as independent variables, select both columns from data. This becomes multiple linear regression.</p><p>x1 = data[[‘SAT’, ‘Rand 1,2,3’]]<br>y = data[‘GPA’]</p><p>x = sm.add_constant(x1)<br>results = sm.OLS(y, x).fit()<br>print(results.summary())</p><p>The model now estimates one coefficient for SAT and another for Rand 1,2,3, plus the intercept. Only include predictors that make sense for your assignment and analysis.</p><h3>9. Common Errors and Quick Fixes</h3><p><strong>Error or symptom</strong></p><p><strong>Likely reason</strong></p><p><strong>What to check</strong></p><p>UFuncTypeError with dtype(‘&lt;U10’)</p><p>Text values were passed where numbers were expected.</p><p>Print x1 and type(x1); make sure you selected data[[‘SAT’]], not a list of column names.</p><p>AttributeError: DataFrame has no attribute ‘dtype’</p><p>Used .dtype on a DataFrame.</p><p>Use .dtypes for a DataFrame; .dtype for a Series or NumPy array.</p><p>ValueError converting to float</p><p>A selected column contains non-numeric text.</p><p>Inspect values; clean or encode text appropriately before conversion.</p><p>Missing-data error</p><p>The selected columns contain NaN values.</p><p>Check data[[‘SAT’, ‘GPA’]].isna().sum() and decide how to handle missing rows.</p><h3>A useful debugging checklist</h3><p>print(type(x1))<br>print(x1.head())<br>print(x1.dtypes) # if x1 is a DataFrame<br>print(y.head())<br>print(y.dtype) # if y is a Series</p><h3>10. A Few Important Things to Remember</h3><p>· A column name is not the same thing as the data stored in that column.</p><p>· data[[‘SAT’]] selects values from the DataFrame; [[‘SAT’]] alone creates a list of text.</p><p>· Check the type and contents of the exact variable passed into a function.</p><p>· X is the predictor; Y is the outcome you want to explain or predict.</p><p>· add_constant() adds the intercept column in this statsmodels workflow.</p><p>· OLS fits the model; .fit() estimates it; summary() reports the results.</p><h3>Conclusion</h3><p>Our error was not really a Linear Regression problem. It was a data-selection problem: the model was receiving text labels instead of the numeric SAT observations. Once we selected the real column with data[[‘SAT’]], the regression workflow could run.</p><p>The biggest lesson for a beginner is simple: before fitting a model, inspect your data, understand the shape of each variable, and make sure you are passing the values you intend to use. Understanding those small steps makes the rest of data analysis much easier.</p><p><em>You can adapt this tutorial to your own dataset by changing the predictor column (SAT), the target column (GPA), and the file-loading step.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e86889804f75" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[python frequently used libraries :]]></title>
            <link>https://medium.com/@maryam.meshref.75/python-frequently-used-libraries-736b24bd3cb8?source=rss-d4aa6cd3974e------2</link>
            <guid isPermaLink="false">https://medium.com/p/736b24bd3cb8</guid>
            <category><![CDATA[python-libraries]]></category>
            <dc:creator><![CDATA[Maryam Meshref ]]></dc:creator>
            <pubDate>Mon, 02 Nov 2026 09:11:08 GMT</pubDate>
            <atom:updated>2026-11-02T09:11:08.755Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Essential Python Machine Learning Ecosystem: A Developer’s Guide</h3><p>Python’s dominance in Machine Learning (ML) and Artificial Intelligence (AI) isn’t just about syntax — it is driven by a powerful, specialized ecosystem of libraries.</p><p>Navigating these tools can be confusing for beginners and intermediate developers alike, as overlapping capabilities often obscure which tool fits which stage. This guide breaks down the essential Python libraries by their primary role in the ML pipeline, clarifying key distinctions along the way.</p><h3>1. Data Processing &amp; Numerical Computation</h3><p>Before training a model, data must be loaded, cleaned, and structured into mathematical representations.</p><h3>NumPy (Numerical Python)</h3><ul><li><strong>Core Concept:</strong> The foundational framework for scientific computing. It introduces the high-performance N-dimensional array object (ndarray).</li><li><strong>Why Use It?</strong> NumPy arrays are implemented in C, storing contiguous memory blocks. This makes operations 10 to 100 times faster than standard Python lists.</li><li><strong>Primary Use Cases:</strong> Vectorized operations, linear algebra, matrix manipulations, and raw numeric preprocessing.</li></ul><h3>Pandas (Panel Data)</h3><ul><li><strong>Core Concept:</strong> The industry standard for structured data manipulation, centered around Series (1D) and DataFrame (2D) structures.</li><li><strong>Why Use It?</strong> It simplifies loading unstructured files, handling missing values (NaN), filtering, aggregating, and merging tabular datasets.</li><li><strong>Primary Use Cases:</strong> Data cleaning, feature engineering, and exploratory data pipelines.</li></ul><blockquote><strong><em>Clearing the Confusion: NumPy vs. Pandas</em></strong></blockquote><ul><li><strong>NumPy</strong> operates on raw, homogenous numerical matrices and handles vector math.</li><li><strong>Pandas</strong> works with heterogeneous, labeled data tables (like Excel or SQL tables).</li><li><em>Note:</em> Pandas is built directly on top of NumPy.</li></ul><h3>2. Data Visualization &amp; Exploratory Analysis</h3><p>Visual analysis helps surface correlations, anomalies, and distributions prior to modeling.</p><h3>Matplotlib</h3><ul><li><strong>Core Concept:</strong> The low-level standard for 2D plotting in Python.</li><li><strong>Why Use It?</strong> Offers granular, pixel-perfect control over every chart element (axes, ticks, legends, and styling).</li><li><strong>Primary Use Cases:</strong> Customized plots, specialized engineering charts, and foundational visualization control.</li></ul><h3>Seaborn</h3><ul><li><strong>Core Concept:</strong> A high-level statistical data visualization library built on top of Matplotlib.</li><li><strong>Why Use It?</strong> Provides visually attractive default themes and concise APIs for complex statistical charts.</li><li><strong>Primary Use Cases:</strong> Heatmaps, correlation matrices, pair plots, and distribution visualizations.</li></ul><blockquote><strong><em>Clearing the Confusion: Matplotlib vs. Seaborn</em></strong></blockquote><blockquote><em>These tools complement rather than compete with each other. Use </em><strong><em>Seaborn</em></strong><em> for fast, beautiful statistical plots with minimal code, and use </em><strong><em>Matplotlib</em></strong><em> when you need precise fine-tuning of layout elements.</em></blockquote><h3>3. Classical Machine Learning</h3><p>When dealing with structured, tabular data or standard predictive tasks, classical ML algorithms remain the most efficient choice.</p><h3>Scikit-Learn (sklearn)</h3><ul><li><strong>Core Concept:</strong> The quintessential library for non-deep machine learning algorithms and preprocessing workflows.</li><li><strong>Primary Use Cases:</strong></li><li><strong>Supervised Learning:</strong> Linear Regression, Decision Trees, Random Forests, Gradient Boosting, and SVMs.</li><li><strong>Unsupervised Learning:</strong> K-Means Clustering, DBSCAN, and Principal Component Analysis (PCA).</li><li><strong>Model Evaluation &amp; Pipelines:</strong> Data splitting (train_test_split), cross-validation, feature scaling, and performance metrics.</li></ul><h3>4. Deep Learning &amp; Neural Networks</h3><p>For unstructured data — such as images, text, audio, and generative AI tasks — deep learning frameworks are required.</p><h3>PyTorch</h3><ul><li><strong>Core Concept:</strong> An open-source deep learning framework developed by Meta AI, known for dynamic computation graphs (imperative execution).</li><li><strong>Why Use It?</strong> Highly pythonic design makes debugging straightforward and intuitive using standard Python tools.</li><li><strong>Primary Use Cases:</strong> AI research, Large Language Models (LLMs), Computer Vision, and custom neural network architectures.</li></ul><h3>TensorFlow &amp; Keras</h3><ul><li><strong>Core Concept:</strong></li><li><strong>TensorFlow:</strong> A comprehensive end-to-end platform developed by Google for high-performance scale and production deployment.</li><li><strong>Keras:</strong> A high-level API (now integrated into TensorFlow) designed for rapid network prototyping.</li><li><strong>Primary Use Cases:</strong> Production-scale deep learning models, cross-platform deployments (mobile/edge), and enterprise neural networks.</li></ul><blockquote><strong><em>Clearing the Confusion: Scikit-Learn vs. PyTorch vs. TensorFlow</em></strong></blockquote><ul><li><strong>Scikit-Learn:</strong> Designed for classical ML on tabular data. It does not train deep neural networks or utilize GPU acceleration.</li><li><strong>PyTorch &amp; TensorFlow:</strong> Built specifically for deep learning, deep neural networks, complex unstructured data, and heavy GPU/TPU hardware acceleration.</li><li><strong>PyTorch</strong> dominates research and cutting-edge generative AI due to its flexibility. <strong>TensorFlow (with Keras)</strong> excels in scalable enterprise production environments.</li></ul><h3><strong>To sum up :</strong></h3><blockquote><strong><em>| Library | Primary Domain | Ideal Scenario |</em></strong></blockquote><blockquote>| **NumPy** | Numerical Math &amp; Linear Algebra | Fast matrix operations on raw arrays |</blockquote><blockquote>| **Pandas** | Tabular Data Processing | Cleaning, transforming, and loading CSV/SQL data |</blockquote><blockquote>| **Matplotlib / Seaborn** | Data Visualization | Exploratory Data Analysis (EDA) &amp; reporting charts |</blockquote><blockquote>| **Scikit-Learn** | Classical Machine Learning | Classification/Regression on structured tabular datasets |</blockquote><blockquote>| **PyTorch / TensorFlow** | Deep Learning &amp; AI | Neural networks, computer vision, NLP, and LLMs |</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=736b24bd3cb8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>