<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: teresa kungu</title>
    <description>The latest articles on Forem by teresa kungu (@teresa_kungu_a8d91b0b7e13).</description>
    <link>https://forem.com/teresa_kungu_a8d91b0b7e13</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3554248%2F1b0c5a4c-070d-4bce-901b-74cc7a64ac87.png</url>
      <title>Forem: teresa kungu</title>
      <link>https://forem.com/teresa_kungu_a8d91b0b7e13</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/teresa_kungu_a8d91b0b7e13"/>
    <language>en</language>
    <item>
      <title>Deploying a Customer Lifetime Value (CLV) Prediction Model Using FastAPI</title>
      <dc:creator>teresa kungu</dc:creator>
      <pubDate>Mon, 09 Feb 2026 14:36:52 +0000</pubDate>
      <link>https://forem.com/teresa_kungu_a8d91b0b7e13/deploying-a-customer-lifetime-value-clv-prediction-model-using-fastapi-3073</link>
      <guid>https://forem.com/teresa_kungu_a8d91b0b7e13/deploying-a-customer-lifetime-value-clv-prediction-model-using-fastapi-3073</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Businesses want to know which customers are most valuable to them. Some customers spend more money, stay longer, and interact more with the business than others. If a company can predict this early, it can make better decisions about marketing, customer support, and retention.&lt;/p&gt;

&lt;p&gt;This is where Customer Lifetime Value (CLV) becomes important. In this project, a machine learning model was built to predict CLV using customer data. The trained model was then deployed using FastAPI, allowing predictions to be made through a simple API.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project Objectives&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Explain what Customer Lifetime Value (CLV) is&lt;/li&gt;
&lt;li&gt;Build a regression model to predict CLV&lt;/li&gt;
&lt;li&gt;Compare models and choose the best one&lt;/li&gt;
&lt;li&gt;Save the trained model for future use&lt;/li&gt;
&lt;li&gt;Deploy the model using FastAPI&lt;/li&gt;
&lt;li&gt;Predict CLV through an APIProject Objectives&lt;/li&gt;
&lt;li&gt;Test the API to confirm it works&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Understanding Customer Lifetime Value (CLV)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Customer Lifetime Value is the total amount of money a business expects to earn from a customer during their entire relationship with the company.&lt;/li&gt;
&lt;li&gt;For example, if a customer spends a small amount every month but stays for many years, their CLV can be high. On the other hand, a customer who spends a lot once but never comes back may have a low CLV.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Predicting CLV helps businesses to&lt;/em&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Identify high-value customers&lt;/li&gt;
&lt;li&gt;Spend marketing money wisely&lt;/li&gt;
&lt;li&gt;Improve customer retention&lt;/li&gt;
&lt;li&gt;Plan better customer engagement strategies&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because CLV is a number, predicting it is a regression problem in machine learning.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dataset and Business Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The dataset used in this project is called &lt;em&gt;customer_lifetime.csv&lt;/em&gt;. Each row represents one customer, and each column describes something about that customer.&lt;/p&gt;

&lt;p&gt;Important columns include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Customer_Age – Age of the customer&lt;/li&gt;
&lt;li&gt;Annual_Income – Yearly income&lt;/li&gt;
&lt;li&gt;Tenure_Months – How long the customer has been active&lt;/li&gt;
&lt;li&gt;Monthly_Spend – Average monthly spending&lt;/li&gt;
&lt;li&gt;Visits_Per_Month – Number of visits per month&lt;/li&gt;
&lt;li&gt;Avg_Basket_Value – Average value per purchase&lt;/li&gt;
&lt;li&gt;Support_Tickets – Number of support issues raised&lt;/li&gt;
&lt;li&gt;CLV – Customer Lifetime Value (target variable)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The main goal is to predict CLV for new customers before spending money on marketing or retention.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data Preparation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first step was to load and explore the dataset to understand the data types and structure. The CLV column was identified as the target, while the remaining columns were used as input features.&lt;/p&gt;

&lt;p&gt;The data was then split into:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Training data – used to teach the model&lt;/li&gt;
&lt;li&gt;Testing data – used to check how well the model performs&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Splitting the data is important because it shows how the model will perform on new, unseen customers.&lt;/p&gt;

&lt;p&gt;Building the Regression Models&lt;/p&gt;

&lt;p&gt;Since CLV is a continuous number, regression models were used.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Two models were built:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Linear Regression&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This model was used as a baseline. It is simple, fast, and easy to understand, but it may not capture complex customer behavior.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Random Forest Regressor&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This model uses many decision trees to make predictions. It handles complex relationships better and usually gives more accurate results.&lt;/p&gt;

&lt;p&gt;Regression is suitable for this problem because the goal is to predict a numeric value, not categories.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Model Evaluation and Selection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Both models were evaluated using regression metrics such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mean Absolute Error (MAE)&lt;/li&gt;
&lt;li&gt;Mean Squared Error (MSE)&lt;/li&gt;
&lt;li&gt;R-squared (R²)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Random Forest model performed better than Linear Regression because it captured more complex patterns in the data. For this reason, it was selected as the final model.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Saving the Model&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The final trained model was saved using Joblib, along with the list of features used during training.&lt;/p&gt;

&lt;p&gt;Saving the model is important because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The model does not need to be retrained every time&lt;/li&gt;
&lt;li&gt;Predictions are consistent&lt;/li&gt;
&lt;li&gt;The API runs faster and more efficiently&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The saved files are stored in a saved_model folder.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Deploying the Model Using FastAPI&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;FastAPI was used to deploy the model as a web API. FastAPI is a Python framework that makes it easy to create APIs and automatically validates input data.&lt;/p&gt;

&lt;p&gt;The model is loaded when the API starts. The model is not retrained inside the API, which follows best practices for production systems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How the API Works&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The API has two main endpoints:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Health Check Endpoint&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;GET /&lt;br&gt;
This endpoint confirms that the API is running correctly.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcjq0p2t28m3cbd4nc3ub.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcjq0p2t28m3cbd4nc3ub.png" alt=" " width="719" height="121"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2.&lt;strong&gt;CLV Prediction Endpoint&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;POST /predict-clv&lt;/p&gt;

&lt;p&gt;This endpoint:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Accepts customer data in JSON format&lt;/li&gt;
&lt;li&gt;Checks if the input data is valid&lt;/li&gt;
&lt;li&gt;Sends the data to the trained model&lt;/li&gt;
&lt;li&gt;Returns the predicted CLV value&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1xnbmhty6136kpabuaez.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1xnbmhty6136kpabuaez.png" alt=" " width="800" height="222"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Testing the API&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The API was tested using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;FastAPI Swagger UI&lt;/li&gt;
&lt;li&gt;Postman&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Successful testing showed that the API correctly accepts input data and returns CLV predictions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion and Future Improvements&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This project shows a complete machine learning process, from understanding customer data to deploying a working prediction API. Predicting CLV helps businesses make smarter and more data-driven decisions.&lt;/p&gt;

&lt;p&gt;In a real business setting, the model could be improved by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Adding more customer behavior data&lt;/li&gt;
&lt;li&gt;Monitoring predictions over time&lt;/li&gt;
&lt;li&gt;Retraining the model with new data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Overall, this project demonstrates how machine learning models can be moved from development into real-world applications using FastAPI.&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>regression</category>
      <category>beginners</category>
      <category>datascience</category>
    </item>
    <item>
      <title>Ridge Regression vs Lasso Regression</title>
      <dc:creator>teresa kungu</dc:creator>
      <pubDate>Mon, 26 Jan 2026 08:01:56 +0000</pubDate>
      <link>https://forem.com/teresa_kungu_a8d91b0b7e13/ridge-regression-vs-lasso-regression-1bne</link>
      <guid>https://forem.com/teresa_kungu_a8d91b0b7e13/ridge-regression-vs-lasso-regression-1bne</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Predicting house prices is a common problem in data science. A house’s price is influenced by many factors such as its size, number of bedrooms, distance to the city, and nearby amenities. However, real-world datasets also contain noise — features that do not truly affect the price.&lt;br&gt;
In this article, we use a house price dataset to explain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ordinary Least Squares (OLS)&lt;/li&gt;
&lt;li&gt;Ridge Regression (L2 Regularization)&lt;/li&gt;
&lt;li&gt;Lasso Regression (L1 Regularization)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The goal is to understand how these models work, why regularization is needed, and which model to choose in practice, using simple explanations and visual support.&lt;br&gt;
&lt;strong&gt;1. Loading the Dataset&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We begin by loading the dataset into Python using common data science libraries. This step allows us to inspect the data and understand what features are available.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The dataset contains 500 houses and includes:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;House characteristics (size, bedrooms, bathrooms)&lt;/li&gt;
&lt;li&gt;Location information (distance to city)&lt;/li&gt;
&lt;li&gt;Social features (schools nearby)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some noisy or weak features that do not meaningfully affect price&lt;br&gt;
Figure 1: Loading the house price dataset and displaying sample rows.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftsaglvo2d2510hv2lmmf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftsaglvo2d2510hv2lmmf.png" alt=" " width="800" height="205"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2*&lt;em&gt;. Understanding the Data&lt;/em&gt;*&lt;/p&gt;

&lt;p&gt;Before building any model, it is important to understand the data.&lt;br&gt;
&lt;strong&gt;Important Features&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;size_sqm – size of the house&lt;/li&gt;
&lt;li&gt;bedrooms – number of bedrooms&lt;/li&gt;
&lt;li&gt;bathrooms – number of bathrooms&lt;/li&gt;
&lt;li&gt;distance_to_city – distance from city center&lt;/li&gt;
&lt;li&gt; schools_nearby – number of nearby schools&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Noisy / Weak Features&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;paint_color_code&lt;/li&gt;
&lt;li&gt;random_id_feature&lt;/li&gt;
&lt;li&gt;weather_noise&lt;/li&gt;
&lt;li&gt;street_code&lt;/li&gt;
&lt;li&gt;Target Variable&lt;/li&gt;
&lt;li&gt;price – the value we want to predict&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some features clearly make sense, while others are random and should not affect house price.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbnnqfqsn2lv9slokxoga.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbnnqfqsn2lv9slokxoga.png" alt=" " width="641" height="587"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Splitting Features and Target&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next, we separate:&lt;/p&gt;

&lt;p&gt;_Input features (X) – all columns except price&lt;/p&gt;

&lt;p&gt;Target (y) – the house price_&lt;/p&gt;

&lt;p&gt;This prepares the data for training machine learning models.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8i5i2onfr2osp7ro5m12.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8i5i2onfr2osp7ro5m12.png" alt=" " width="800" height="77"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Train–Test Split&lt;/strong&gt;&lt;br&gt;
To evaluate model performance properly, we split the dataset into:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Training data– used to train the model&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Testing data –used to evaluate performance on unseen data&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This step is critical for detecting &lt;strong&gt;overfitting.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F105gat0szq7iexi6wuos.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F105gat0szq7iexi6wuos.png" alt=" " width="800" height="198"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Ordinary Least Squares (OLS)&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;What is OLS?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Ordinary Least Squares is the most basic linear regression method. It finds model coefficients by minimizing the sum of squared differences between actual house prices and predicted prices.&lt;br&gt;
&lt;strong&gt;Why OLS Can Overfit&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;OLS:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Uses all features&lt;/li&gt;
&lt;li&gt;Assigns coefficients to both useful and noisy variables&lt;/li&gt;
&lt;li&gt;Can give large weights to irrelevant features&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In our dataset, OLS may treat random_id_feature as important, even though it has no real meaning.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Detecting Overfitting with OLS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To check overfitting, we compare:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Training performance&lt;/li&gt;
&lt;li&gt;Testing performance&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If training accuracy is high but test accuracy is much lower, the model is overfitting.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvf27ajjbb8eu9dyu03ab.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvf27ajjbb8eu9dyu03ab.png" alt=" " width="800" height="273"&gt;&lt;/a&gt;&lt;br&gt;
**&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Regularization: Why We Need It**&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Regularization adds a penalty to the loss function to control model complexity.&lt;/p&gt;

&lt;p&gt;It helps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reduce overfitting&lt;/li&gt;
&lt;li&gt;Shrink large coefficients&lt;/li&gt;
&lt;li&gt;Improve performance on unseen data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Two common regularization techniques are** Ridge and Lasso regression.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. Ridge Regression (L2 Regularization)&lt;/strong&gt;&lt;br&gt;
How Ridge Works&lt;/p&gt;

&lt;p&gt;Ridge regression adds an L2 penalty, which penalizes large coefficients by squaring them.&lt;/p&gt;

&lt;p&gt;Ridge:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Shrinks all coefficients&lt;/li&gt;
&lt;li&gt;Keeps all features&lt;/li&gt;
&lt;li&gt;Reduces sensitivity to noise&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ridge on Our Dataset&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In our house price data:&lt;/p&gt;

&lt;p&gt;Important features still have strong influence&lt;/p&gt;

&lt;p&gt;Noisy features receive very small coefficients&lt;/p&gt;

&lt;p&gt;No feature is completely removed&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5mw1vt62p8tji2pludi9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5mw1vt62p8tji2pludi9.png" alt=" " width="800" height="241"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;9. Lasso Regression (L1 Regularization)&lt;/strong&gt;&lt;br&gt;
How Lasso Works&lt;/p&gt;

&lt;p&gt;Lasso regression uses an L1 penalty, which can shrink coefficients to zero.&lt;/p&gt;

&lt;p&gt;This means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Unimportant features are removed&lt;/li&gt;
&lt;li&gt;The model becomes simpler and easier to interpret&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Lasso on Our Dataset&lt;/p&gt;

&lt;p&gt;After applying Lasso:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Features like size_sqm and bedrooms remain&lt;/li&gt;
&lt;li&gt;Noisy features such as weather_noise and random_id_feature are set to zero&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzec929mdorimk5bli8ts.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzec929mdorimk5bli8ts.png" alt=" " width="800" height="244"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frdydyi1kv3rpp012plu9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frdydyi1kv3rpp012plu9.png" alt=" " width="800" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzzlu0e8e8aj8hq3d0s2g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzzlu0e8e8aj8hq3d0s2g.png" alt=" " width="723" height="517"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;10. Ridge vs Lasso Comparison&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Aspect&lt;/th&gt;
&lt;th&gt;Ridge Regression&lt;/th&gt;
&lt;th&gt;Lasso Regression&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Regularization&lt;/td&gt;
&lt;td&gt;L2&lt;/td&gt;
&lt;td&gt;L1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Feature selection&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Handles noise&lt;/td&gt;
&lt;td&gt;Shrinks&lt;/td&gt;
&lt;td&gt;Removes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Interpretability&lt;/td&gt;
&lt;td&gt;Lower&lt;/td&gt;
&lt;td&gt;Higher&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;11. Model Evaluation Using Residuals&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Residuals are the differences between:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Actual house prices&lt;/li&gt;
&lt;li&gt;Predicted house prices&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By plotting residuals:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Random scatter → good model&lt;/li&gt;
&lt;li&gt;Clear patterns → poor model fit&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;12. Choosing the Right Model&lt;/strong&gt;&lt;br&gt;
If all features are believed to matter&lt;/p&gt;

&lt;p&gt;Choose Ridge Regression&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keeps all features&lt;/li&gt;
&lt;li&gt;Controls overfitting&lt;/li&gt;
&lt;li&gt;Works well with correlated variables&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If only a few features are important&lt;/p&gt;

&lt;p&gt;Choose Lasso Regression&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Removes noisy features&lt;/li&gt;
&lt;li&gt;Produces a simpler model&lt;/li&gt;
&lt;li&gt;Easier to explain and interpret&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Using the house price dataset, we observe that:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;OLS&lt;/strong&gt; is simple but prone to overfitting&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ridge regression&lt;/strong&gt; improves stability by shrinking coefficients&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lasso regression&lt;/strong&gt; simplifies the model by removing irrelevant features&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>linearregression</category>
      <category>regressionanalysis</category>
      <category>lassoregression</category>
    </item>
    <item>
      <title>Understanding Classes in Object-Oriented Programming: A Beginner's Guide</title>
      <dc:creator>teresa kungu</dc:creator>
      <pubDate>Sun, 14 Dec 2025 17:30:48 +0000</pubDate>
      <link>https://forem.com/teresa_kungu_a8d91b0b7e13/understanding-classes-in-object-oriented-programming-a-beginners-guide-a1d</link>
      <guid>https://forem.com/teresa_kungu_a8d91b0b7e13/understanding-classes-in-object-oriented-programming-a-beginners-guide-a1d</guid>
      <description>&lt;p&gt;&lt;strong&gt;Object-Oriented Programming (OOP)&lt;/strong&gt; is a programming approach that helps us organize code by modeling real-world concepts. One of the most important ideas in OOP is the class.&lt;br&gt;
&lt;strong&gt;&lt;em&gt;What Is a Class?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;class&lt;/strong&gt; is a blueprint or template used to create objects. It defines what data an object should store and what actions it can perform. The class itself is not an object; instead, it describes how objects of that type should behave.&lt;/p&gt;

&lt;p&gt;For example, if we want to represent a bank account in a program, we can create a BankAccount class. This class will describe what every bank account has (such as an account number and balance) and what it can do (such as depositing or withdrawing money).&lt;br&gt;
&lt;strong&gt;Why Are Classes Useful?&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Classes help programmers:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Organize code in a clear and logical way&lt;/li&gt;
&lt;li&gt;Avoid repeating the same code multiple times&lt;/li&gt;
&lt;li&gt;Model real-world entities more naturally&lt;/li&gt;
&lt;li&gt;Make programs easier to read, maintain, and extend&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead of writing many unrelated variables and functions, classes group related data and behavior together.&lt;br&gt;
Attributes and Methods&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Attributes&lt;/strong&gt; are variables that store data about an object.&lt;br&gt;
Example: account number, owner name, balance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Methods&lt;/strong&gt; are functions defined inside a class that describe what the object can do.&lt;br&gt;
Example: deposit money, withdraw money, check balance.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Together, attributes and methods describe both the state and behavior of an object.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example: A BankAccount Class&lt;/p&gt;

&lt;p&gt;Below is a simple example using Python:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvmt278i870x06x9mkj23.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvmt278i870x06x9mkj23.png" alt=" " width="800" height="591"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;init&lt;/strong&gt; method is a special method that runs when a new object is created. It initializes the account number, owner, and balance.&lt;/li&gt;
&lt;li&gt;deposit() adds money to the account.&lt;/li&gt;
&lt;li&gt;withdraw() removes money if there is enough balance.&lt;/li&gt;
&lt;li&gt;check_balance() displays the current balance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Creating an Object from the Class&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once the class is defined, a student can create an object (also called an instance) from it:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn4akgnbdc1h9mrie9vfd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn4akgnbdc1h9mrie9vfd.png" alt=" " width="800" height="114"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now account1 is a real bank account created from the blueprint.&lt;br&gt;
Using the Object&lt;/p&gt;

&lt;p&gt;The student can now call the methods of the object:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9noxa9v7f2z6mmpwaktm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9noxa9v7f2z6mmpwaktm.png" alt=" " width="800" height="288"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each object created from the class has its own data and can perform actions independently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Classes are a powerful way to structure programs by modeling real-world problems. They combine data (attributes) and behavior (methods) into a single, logical unit. By using classes like BankAccount, beginners can clearly see how OOP helps create organized, reusable, and easy-to-understand code. As programs grow larger, classes become essential for building clean and maintainable software.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>productivity</category>
      <category>beginners</category>
    </item>
    <item>
      <title>##How to Connect Power BI to Aiven PostgreSQL</title>
      <dc:creator>teresa kungu</dc:creator>
      <pubDate>Sun, 23 Nov 2025 05:42:08 +0000</pubDate>
      <link>https://forem.com/teresa_kungu_a8d91b0b7e13/how-to-connect-power-bi-to-aiven-postgresql-2b0l</link>
      <guid>https://forem.com/teresa_kungu_a8d91b0b7e13/how-to-connect-power-bi-to-aiven-postgresql-2b0l</guid>
      <description>&lt;h2&gt;
  
  
  📌 Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Power BI Desktop installed&lt;/li&gt;
&lt;li&gt;PostgreSQL (local or Aiven)&lt;/li&gt;
&lt;li&gt;Basic understanding of database credentials (host, username, password)&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  🟦 1. Connect Power BI to Local PostgreSQL
&lt;/h1&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;1. Install PostgreSQL ODBC Driver&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Download and install the PostgreSQL ODBC driver (psqlODBC) from the official PostgreSQL website.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2Fc7b335a5-476d-4917-963c-183c87975f74" class="article-body-image-wrapper"&gt;&lt;img alt="image" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2Fc7b335a5-476d-4917-963c-183c87975f74" width="1854" height="517"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;2. Gather Local Connection Details&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Make sure you have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Host: localhost
Port: 5432
Database: your_database_name
Username: your_username
Password: your_password
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;3. Connect Power BI to Local PostgreSQL&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Open Power BI Desktop&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Get Data → More...&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;PostgreSQL database&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2Fbb357749-0cac-47b0-8dc4-6b1bb2474e16" class="article-body-image-wrapper"&gt;&lt;img alt="image" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2Fbb357749-0cac-47b0-8dc4-6b1bb2474e16" width="955" height="814"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Enter your connection details:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Server: localhost
Database: your_database_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Click &lt;strong&gt;OK&lt;/strong&gt; and enter your username &amp;amp; password.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;4. Load Tables&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Power BI will display all tables in your PostgreSQL database.&lt;/p&gt;

&lt;p&gt;Select the tables you want → click &lt;strong&gt;Load&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;`&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftfo7xyahry7zanri07ap.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftfo7xyahry7zanri07ap.png" alt=" " width="800" height="637"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  🟦 2. Connect Power BI to Aiven PostgreSQL (Cloud)
&lt;/h1&gt;

&lt;p&gt;Aiven requires SSL, but the setup is straightforward.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;1. Get Aiven PostgreSQL Credentials&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;From your Aiven dashboard:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open your PostgreSQL service&lt;/li&gt;
&lt;li&gt;Go to &lt;strong&gt;Overview&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Copy your connection details:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Host&lt;/li&gt;
&lt;li&gt;Port&lt;/li&gt;
&lt;li&gt;Database&lt;/li&gt;
&lt;li&gt;Username&lt;/li&gt;
&lt;li&gt;Password&lt;/li&gt;
&lt;li&gt;SSL mode (Required)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2F0064b487-8475-4cca-aff8-eafb8fbfad66" class="article-body-image-wrapper"&gt;&lt;img alt="image" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2F0064b487-8475-4cca-aff8-eafb8fbfad66" width="1407" height="560"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;2. Connect Power BI to Aiven with SSL Enabled&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Open &lt;strong&gt;Get Data → PostgreSQL database&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Enter:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
Server: your-service-name.aivencloud.com&lt;br&gt;
Database: defaultdb&lt;br&gt;
Port: your_port&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open &lt;strong&gt;Advanced options&lt;/strong&gt; and add:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
SSL Mode=Require&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click &lt;strong&gt;OK&lt;/strong&gt; → Enter your password.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;3. SSL Troubleshooting&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;If you get certificate errors, try:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
SSL Mode=Verify-Full&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;or download the Aiven CA certificate and configure it.&lt;/p&gt;




&lt;h1&gt;
  
  
  🟦 Optional: Use Connection Strings
&lt;/h1&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Local PostgreSQL:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
Server=localhost;Port=5432;Database=myDB;UID=myUser;PWD=myPassword;&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Aiven PostgreSQL:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
Server=your-host.aivencloud.com;Port=12345;Database=defaultdb;UID=avnadmin;PWD=yourPassword;SSL Mode=Require;&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  🟦 Power Query (M Code) Example
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;m&lt;br&gt;
let&lt;br&gt;
    Source = Postgres.Database(&lt;br&gt;
        "your-host.aivencloud.com",&lt;br&gt;
        "defaultdb",&lt;br&gt;
        [&lt;br&gt;
            Port=12345,&lt;br&gt;
            SSLMode=1,&lt;br&gt;
            User="avnadmin"&lt;br&gt;
        ]&lt;br&gt;
    )&lt;br&gt;
in&lt;br&gt;
    Source&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  🟦 Best Practices
&lt;/h1&gt;

&lt;h3&gt;
  
  
  🔐 Security
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Never publish passwords in articles or dashboards&lt;/li&gt;
&lt;li&gt;Use Power BI Gateway for scheduled refresh&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ⚡ Performance
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;strong&gt;DirectQuery&lt;/strong&gt; for real-time dashboards&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;Import mode&lt;/strong&gt; for better performance on large mode&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  🟦 Conclusion
&lt;/h1&gt;

&lt;p&gt;You now know how to connect Power BI to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Local PostgreSQL&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Aiven PostgreSQL (with SSL)&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This simple setup allows you to start building powerful dashboards quickly.&lt;/p&gt;

</description>
      <category>career</category>
      <category>beginners</category>
      <category>science</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Power BI and DAX: Making Data Easy to Understand</title>
      <dc:creator>teresa kungu</dc:creator>
      <pubDate>Wed, 08 Oct 2025 22:21:03 +0000</pubDate>
      <link>https://forem.com/teresa_kungu_a8d91b0b7e13/power-bi-and-dax-making-data-easy-to-understand-5agg</link>
      <guid>https://forem.com/teresa_kungu_a8d91b0b7e13/power-bi-and-dax-making-data-easy-to-understand-5agg</guid>
      <description>&lt;p&gt;What is Power BI and Why is it Important?&lt;/p&gt;

&lt;p&gt;Imagine you have a lot of numbers and information, like records of crops grown in different Kenyan counties. It can be hard to see the story in all that data. Power BI is a tool from Microsoft that turns this raw data into easy-to-understand visuals like charts and maps. Instead of looking at confusing spreadsheets, you can see a clear dashboard that shows you exactly what’s happening.&lt;/p&gt;

&lt;p&gt;What is DAX and What Makes it Powerful?&lt;/p&gt;

&lt;p&gt;DAX (Data Analysis Expressions) is the special language used in Power BI to create calculations. Think of it as the "brain" that works behind the scenes. If Power BI is the car, DAX is the engine. It helps you ask complex questions about your data and get clear answers.&lt;/p&gt;

&lt;p&gt;Here are some simple examples using a Kenya Crops dataset:&lt;/p&gt;

&lt;p&gt;Mathematical Functions&lt;/p&gt;

&lt;p&gt;SUM: Adds up the total harvest.&lt;br&gt;
Example: Total Harvest = SUM(Crops[Yield])&lt;/p&gt;

&lt;p&gt;AVERAGE: Finds the average yield per farm.&lt;br&gt;
Example: Average Yield = AVERAGE(Crops[Yield])&lt;/p&gt;

&lt;p&gt;Text Functions&lt;/p&gt;

&lt;p&gt;LEFT / RIGHT: Gets part of a text. You could extract a county code from a longer name.&lt;/p&gt;

&lt;p&gt;CONCATENATE: Joins text together, like combining a county name and a crop type into one description.&lt;/p&gt;

&lt;p&gt;Date &amp;amp; Time Functions&lt;/p&gt;

&lt;p&gt;YEAR: Extracts the year from a date to see trends over time.&lt;/p&gt;

&lt;p&gt;TOTALYTD: Calculates the total yield from the start of the year up to today.&lt;br&gt;
Example: Year-to-Date Harvest = TOTALYTD(SUM(Crops[Yield]), Dates[Date])&lt;/p&gt;

&lt;p&gt;SAMEPERIODLASTYEAR: Compares this season's harvest to the last one.&lt;br&gt;
Example: Sales LY = CALCULATE(SUM(Crops[Yield]), SAMEPERIODLASTYEAR(Dates[Date]))&lt;/p&gt;

&lt;p&gt;Logical Functions&lt;/p&gt;

&lt;p&gt;IF: Makes decisions with data.&lt;br&gt;
Example: High Yield = IF(Crops[Yield] &amp;gt; 1000, "High", "Low")&lt;/p&gt;

&lt;p&gt;SWITCH: Chooses from multiple options, like categorizing crops into types.&lt;/p&gt;

&lt;p&gt;How Does This Help?&lt;/p&gt;

&lt;p&gt;For a farmer or agribusiness, this is a game-changer. With Power BI and DAX, they can:&lt;/p&gt;

&lt;p&gt;Instantly see which crop is most profitable in their region.&lt;/p&gt;

&lt;p&gt;Compare this year's harvest to last year's to measure progress.&lt;/p&gt;

&lt;p&gt;Identify the best and worst-performing seasons.&lt;/p&gt;

&lt;p&gt;My Personal Insight&lt;/p&gt;

&lt;p&gt;The real value of Power BI and DAX isn't just in making pretty charts. It's in saving time and making smarter decisions. Instead of guessing, farmers and business owners can use data to know exactly what to plant, when to sell, and where to focus their efforts. It turns uncertainty into a clear plan for success&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>datascience</category>
      <category>tools</category>
    </item>
  </channel>
</rss>
