In this article, you will learn how MinMaxScaler, StandardScaler, and RobustScaler transform skewed, outlier-heavy data, and how to pick the right one for your modeling pipeline. Topics we will cover include: How each scaler works and where it breaks on skewed or outlier-rich data A realistic synthetic dataset to stress-test the scalers A practical, code-ready heuristic for choosing a scaler Let’s not waste any more time. MinMax vs Standard vs Robust Scaler: Which One Wins for Skewed Data?Image by Editor Introduction You’ve loaded your dataset and the distribution plots look rough. Heavy right tail, some obvious outliers, and that familiar sinking feeling that your model performance is sure to be suboptimal. Been there? Choosing the right scaler for skewed data isn’t just about following best practices. It’s about understanding what each method actually does to your data and when those transformations help versus hurt your model’s ability to learn meaningful patterns. In this article, we’ll test MinMaxScaler, StandardScaler, and RobustScaler on realistic data, see exactly what happens under the hood, and give you a practical decision framework for your next project. Let’s begin! 🔗 Link to the code on GitHub Understanding How Common Data Scalers Work Let’s start by understanding how the different scalers work, their advantages and disadvantages. MinMax Scaler MinMax Scaler squashes everything into a fixed range, usually [0,1], using your data’s minimum and maximum values. scaled_value = (value – min) / (max – min) MinMaxScaler has the following advantages: Bounded output range [0,1] Preserves original data relationships Fast and simple to understand The problem: Extreme outliers make the denominator massive, compressing most of your actual data into a tiny fraction of the available range. Standard Scaler Standard Scaler centers data around zero with unit variance by subtracting the mean and dividing by standard deviation. scaled_value = (value – mean) / standard_deviation StandardScaler has the following advantages: Works great with normally distributed data Centers data around zero Well-understood by most teams The problem: Both mean and standard deviation are heavily influenced by outliers, skewing the scaling for normal data points. Robust Scaler Robust Scaler uses the median and interquartile range (IQR) instead of the mean and standard deviation, which are susceptible to outliers. scaled_value = (value – median) / IQR IQR = Q3 – Q1 where: Q1 = First quartile (25th percentile) – the value below which 25% of data falls Q3 = Third quartile (75th percentile) – the value below which 75% of data falls RobustScaler has the following advantages: Resistant to outliers Uses percentiles (25th and 75th) that ignore extreme values Preserves data distribution shape The problem: It has an unbounded output range, which can be less intuitive to interpret. Creating Sample Data Let’s create a dataset that actually reflects what you’ll encounter in production. We’ll combine three common data patterns: normal user behavior, naturally skewed distributions (like revenue or page views), and those extreme outliers that always seem to sneak into real datasets. We’ll use NumPy, Pandas, Matplotlib, and SciPy. import numpy as np import pandas as pd import matplotlib.pyplot as plt from sklearn.preprocessing import MinMaxScaler, StandardScaler, RobustScaler from scipy import stats np.random.seed(42) # Simulate typical user behavior patterns normal_data = np.random.normal(50, 15, 800) # Add natural skew (common in revenue, pageviews, etc.) skewed_data = np.random.exponential(2, 800) * 10 + 20 # Include inevitable extreme outliers outliers = [200, 180, 190, 210, 195] # Combine into one messy dataset data = np.concatenate([normal_data, skewed_data, outliers]) df = pd.DataFrame({‘original’: data}) # Apply all three scalers scalers = { ‘MinMax’: MinMaxScaler(), ‘Standard’: StandardScaler(), ‘Robust’: RobustScaler() } for name, scaler in scalers.items(): df[name] = scaler.fit_transform(df[[‘original’]]).flatten() # Check what we’re working with print(“Original Data Stats:”) print(f”Mean: {df[‘original’].mean():.2f}”) print(f”Median: {df[‘original’].median():.2f}”) print(f”Std Dev: {df[‘original’].std():.2f}”) print(f”Skewness: {stats.skew(df[‘original’]):.2f}”) print(f”Range: {df[‘original’].min():.1f} to {df[‘original’].max():.1f}”) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 import numpy as np import pandas as pd import matplotlib.pyplot as plt from sklearn.preprocessing import MinMaxScaler, StandardScaler, RobustScaler from scipy import stats np.random.seed(42) # Simulate typical user behavior patterns normal_data = np.random.normal(50, 15, 800) # Add natural skew (common in revenue, pageviews, etc.) skewed_data = np.random.exponential(2, 800) * 10 + 20 # Include inevitable extreme outliers outliers = [200, 180, 190, 210, 195] # Combine into one messy dataset data = np.concatenate([normal_data, skewed_data, outliers]) df = pd.DataFrame({‘original’: data}) # Apply all three scalers scalers = { ‘MinMax’: MinMaxScaler(), ‘Standard’: StandardScaler(), ‘Robust’: RobustScaler() } for name, scaler in scalers.items(): df[name] = scaler.fit_transform(df[[‘original’]]).flatten() # Check what we’re working with print(“Original Data Stats:”) print(f“Mean: {df[‘original’].mean():.2f}”) print(f“Median: {df[‘original’].median():.2f}”) print(f“Std Dev: {df[‘original’].std():.2f}”) print(f“Skewness: {stats.skew(df[‘original’]):.2f}”) print(f“Range: {df[‘original’].min():.1f} to {df[‘original’].max():.1f}”) Here’s the info for the sample dataset: Original Data Stats: Mean: 45.65 Median: 42.81 Std Dev: 20.52 Skewness: 2.07 Range: 1.4 to 210.0 Original Data Stats: Mean: 45.65 Median: 42.81 Std Dev: 20.52 Skewness: 2.07 Range: 1.4 to 210.0 What Actually Happens During Data Scaling Let’s take a look at the numbers to understand exactly what each scaler is doing to our data. The statistics will reveal why some scalers fail with skewed data while others handle it quite well. Effect of MinMax Scaler on Sample Data First, let’s examine how MinMaxScaler’s reliance on min/max values creates problems when outliers are present. print(“=== MinMaxScaler Analysis ===”) min_val = df[‘original’].min() max_val = df[‘original’].max() print(f”Scaling range: {min_val:.1f} to {max_val:.1f}”) # Show the compression effect percentiles = [50, 75, 90, 95, 99] for p in percentiles: pct_val = df[‘MinMax’].quantile(p/100) print(f”{p}% of data falls below: {pct_val:.3f}”) data_below_half = (df[‘MinMax’] < 0.5).sum() / len(df) * 100 print(f”\nResult: {data_below_half:.1f}% of data compressed below 0.5″) print(“=== MinMaxScaler Analysis ===”) min_val = df[‘original’].min() max_val = df[‘original’].max() print(f“Scaling range: {min_val:.1f} to {max_val:.1f}”) # Show the compression effect percentiles = [50, 75, 90, 95, 99] for p in percentiles: pct_val = df[‘MinMax’].quantile(p/100) print(f“{p}% of data falls below: {pct_val:.3f}”) data_below_half =
Meta Lays Off 600 Employees Amid AI Labs Reorganisation, Focuses On Next-Gen Models | Technology News
Meta Layoffs 2025: Meta, the parent company of Facebook and Instagram, has announced to cut off around 600 positions in its Superintelligence Labs, the company said on Wednesday. The move is part of a reorganisation aimed at making the artificial intelligence (AI) unit more flexible and efficient, reported by Reuters. The job cuts will affect several parts of Meta’s AI division, including the Facebook Artificial Intelligence Research (FAIR) unit, as well as teams working on product-related AI and AI infrastructure. However, the newly formed TBD Lab, which includes a small team of researchers and engineers developing Meta’s next-generation AI foundation models, will not be affected. Chief AI Officer Alexandr Wang said that reducing team sizes will help streamline decision-making and give each remaining team member greater responsibility, scope, and impact. Meta is also encouraging employees affected by the cuts to apply for other positions within the company. Add Zee News as a Preferred Source Restructuring Follows Llama 4 Reception The reorganisation has come months after Meta consolidated its AI efforts under the Superintelligence Labs in June. This restructuring followed the departure of some senior staff and a lukewarm reception for its open-source Llama 4 AI model. CEO Mark Zuckerberg had previously led an aggressive hiring drive to strengthen the company’s AI capabilities. (Also Read: ChatGPT Kicked Off WhatsApp: Meta Bans AI Bots – Will Your Chats Survive After Jan 15?) Superintelligence Labs now includes Meta’s foundation, product, and FAIR teams, alongside the TBD Lab, which is focused on creating the next generation of AI models. Meta’s AI journey began in 2013 when it launched the FAIR unit and hired Yann LeCun as chief AI scientist. Since then, the company has built a global research network focused on deep learning. Reorganisation Comes Amid Big Financing Deal The announcement also comes shortly after Meta secured a $27 billion financing deal with Blue Owl Capital, the company’s largest-ever private capital agreement. The deal will fund Meta’s biggest data center project, with analysts noting it allows the company to pursue its AI ambitions while shifting much of the upfront cost and risk to external investors.
7 Pandas Tricks to Handle Large Datasets
7 Pandas Tricks to Handle Large DatasetsImage by Editor Introduction Large dataset handling in Python is not exempt from challenges like memory constraints and slow processing workflows. Thankfully, the versatile and surprisingly capable Pandas library provides specific tools and techniques for dealing with large — and often complex and challenging in nature — datasets, including tabular, text, or time-series data. This article illustrates 7 tricks offered by this library to efficiently and effectively manage such large datasets. 1. Chunked Dataset Loading By using the chunksize argument in Pandas’ read_csv() function to read datasets contained in CSV files, we can load and process large datasets in smaller, more manageable chunks of a specified size. This helps prevent issues like memory overflows. import pandas as pd def process(chunk): “””Placeholder function that you may replace with your actual code for cleaning and processing each data chunk.””” print(f”Processing chunk of shape: {chunk.shape}”) chunk_iter = pd.read_csv(“https://raw.githubusercontent.com/frictionlessdata/datasets/main/files/csv/10mb.csv”, chunksize=100000) for chunk in chunk_iter: process(chunk) import pandas as pd def process(chunk): “”“Placeholder function that you may replace with your actual code for cleaning and processing each data chunk.”“” print(f“Processing chunk of shape: {chunk.shape}”) chunk_iter = pd.read_csv(“https://raw.githubusercontent.com/frictionlessdata/datasets/main/files/csv/10mb.csv”, chunksize=100000) for chunk in chunk_iter: process(chunk) 2. Downcasting Data Types for Memory Efficiency Optimization Tiny changes can make a big difference when they are applied to a large number of data elements. This is the case when converting data types to a lower-bit representation using functions like astype(). Simple yet very effective, as shown below. For this example, let’s load the dataset into a Pandas dataframe (without chunking, for the sake of simplicity in explanations): url = “https://raw.githubusercontent.com/frictionlessdata/datasets/main/files/csv/10mb.csv” df = pd.read_csv(url) df.info() url = “https://raw.githubusercontent.com/frictionlessdata/datasets/main/files/csv/10mb.csv” df = pd.read_csv(url) df.info() # Initial memory usage print(“Before optimization:”, df.memory_usage(deep=True).sum() / 1e6, “MB”) # Downcasting the type of numeric columns for col in df.select_dtypes(include=[“int”]).columns: df[col] = pd.to_numeric(df[col], downcast=”integer”) for col in df.select_dtypes(include=[“float”]).columns: df[col] = pd.to_numeric(df[col], downcast=”float”) # Converting object/string columns with few unique values to categorical for col in df.select_dtypes(include=[“object”]).columns: if df[col].nunique() / len(df) < 0.5: df[col] = df[col].astype(“category”) print(“After optimization:”, df.memory_usage(deep=True).sum() / 1e6, “MB”) # Initial memory usage print(“Before optimization:”, df.memory_usage(deep=True).sum() / 1e6, “MB”) # Downcasting the type of numeric columns for col in df.select_dtypes(include=[“int”]).columns: df[col] = pd.to_numeric(df[col], downcast=“integer”) for col in df.select_dtypes(include=[“float”]).columns: df[col] = pd.to_numeric(df[col], downcast=“float”) # Converting object/string columns with few unique values to categorical for col in df.select_dtypes(include=[“object”]).columns: if df[col].nunique() / len(df) < 0.5: df[col] = df[col].astype(“category”) print(“After optimization:”, df.memory_usage(deep=True).sum() / 1e6, “MB”) Try it yourself and notice the substantial difference in efficiency. 3. Using Categorical Data for Frequently Occurring Strings Handling attributes containing repeated strings in a limited fashion is made more efficient by mapping them into categorical data types, namely by encoding strings into integer identifiers. This is how it can be done, for example, to map the names of the 12 zodiac signs into categorical types using the publicly available horoscope dataset: import pandas as pd url=”https://raw.githubusercontent.com/plotly/datasets/refs/heads/master/horoscope_data.csv” df = pd.read_csv(url) # Convert ‘sign’ column to ‘category’ dtype df[‘sign’] = df[‘sign’].astype(‘category’) print(df[‘sign’]) import pandas as pd url = ‘https://raw.githubusercontent.com/plotly/datasets/refs/heads/master/horoscope_data.csv’ df = pd.read_csv(url) # Convert ‘sign’ column to ‘category’ dtype df[‘sign’] = df[‘sign’].astype(‘category’) print(df[‘sign’]) 4. Saving Data in Efficient Format: Parquet Parquet is a binary columnar dataset format that contributes to much faster file reading and writing than plain CSV. Therefore, it might be a preferred option worth considering for very large files. Repeated strings like the zodiac signs in the horoscope dataset introduced earlier are also internally compressed to further simplify memory usage. Note that writing/reading Parquet in Pandas requires an optional engine such as pyarrow or fastparquet to be installed. # Saving dataset as Parquet df.to_parquet(“horoscope.parquet”, index=False) # Reloading Parquet file efficiently df_parquet = pd.read_parquet(“horoscope.parquet”) print(“Parquet shape:”, df_parquet.shape) print(df_parquet.head()) # Saving dataset as Parquet df.to_parquet(“horoscope.parquet”, index=False) # Reloading Parquet file efficiently df_parquet = pd.read_parquet(“horoscope.parquet”) print(“Parquet shape:”, df_parquet.shape) print(df_parquet.head()) 5. GroupBy Aggregation Large dataset analysis usually involves obtaining statistics for summarizing categorical columns. Having previously converted repeated strings to categorical columns (trick 3) has follow-up benefits in processes like grouping data by category, as illustrated below, where we aggregate horoscope instances per zodiac sign: numeric_cols = df.select_dtypes(include=[‘float’, ‘int’]).columns.tolist() # Perform groupby aggregation safely if numeric_cols: agg_result = df.groupby(‘sign’)[numeric_cols].mean() print(agg_result.head(12)) else: print(“No numeric columns available for aggregation.”) numeric_cols = df.select_dtypes(include=[‘float’, ‘int’]).columns.tolist() # Perform groupby aggregation safely if numeric_cols: agg_result = df.groupby(‘sign’)[numeric_cols].mean() print(agg_result.head(12)) else: print(“No numeric columns available for aggregation.”) Note that the aggregation used, an arithmetic mean, affects purely numerical features in the dataset: in this case, the lucky number in each horoscope. It may not make too much sense to average these lucky numbers, but the example is just for the sake of playing with the dataset and illustrating what can be done with large datasets more efficiently. 6. query() and eval() for Efficient Filtering and Computation We will add a new, synthetic numerical feature to our horoscope dataset to illustrate how the use of the aforementioned functions can make filtering and other computations faster at scale. The query() function is used to filter rows that accomplish a condition, and the eval() function applies computations, typically among multiple numeric features. Both functions are designed to handle large datasets efficiently: df[‘lucky_number_squared’] = df[‘lucky_number’] ** 2 print(df.head()) numeric_cols = df.select_dtypes(include=[‘float’, ‘int’]).columns.tolist() if len(numeric_cols) >= 2: col1, col2 = numeric_cols[:2] df_filtered = df.query(f”{col1} > 0 and {col2} > 0″) df_filtered = df_filtered.assign(Computed=df_filtered.eval(f”{col1} + {col2}”)) print(df_filtered[[‘sign’, col1, col2, ‘Computed’]].head()) else: print(“Not enough numeric columns for demo.”) df[‘lucky_number_squared’] = df[‘lucky_number’] ** 2 print(df.head()) numeric_cols = df.select_dtypes(include=[‘float’, ‘int’]).columns.tolist() if len(numeric_cols) >= 2: col1, col2 = numeric_cols[:2] df_filtered = df.query(f“{col1} > 0 and {col2} > 0”) df_filtered = df_filtered.assign(Computed=df_filtered.eval(f“{col1} + {col2}”)) print(df_filtered[[‘sign’, col1, col2, ‘Computed’]].head()) else: print(“Not enough numeric columns for demo.”) 7. Vectorized String Operations for Efficient Column Transformations Performing vectorized operations on strings in pandas datasets is a seamless and almost transparent process that is more efficient than manual alternatives like loops. This
Best Phones Under ₹10,000 With 5000mAh Battery: 5 Power-Packed Picks For You | Technology News
Looking for a powerful smartphone that fits your budget? In 2025, several brands are offering feature-packed 5G phones under ₹10,000 — combining big batteries, vibrant displays, and solid performance. If you want a phone that lasts long, runs smoothly, and looks premium, here are the Top 5 Smartphones Under ₹10,000 With 5000mAh Battery you can consider! 1. Xiaomi Redmi 13C 5G Add Zee News as a Preferred Source Price: ₹9,999/- The Xiaomi Redmi 13C 5G is one of the best options for budget users seeking 5G connectivity with reliable performance. Featuring a 6.74-inch 90Hz IPS LCD display protected by Gorilla Glass 3, it ensures durability and smooth visuals. Powered by the MediaTek Dimensity 6100+ (6nm) chipset, the phone runs on Android 13 with MIUI 14 for a clean experience. It comes with multiple RAM variants up to 8GB and storage up to 256GB (UFS 2.2), ensuring fast app performance. The 50MP main camera delivers sharp photos, and its 5000mAh battery with 18W charging lasts easily through the day. Colors: Starry Black, Twilight Blue, Startrail Green Highlight: Reliable 5G performance and strong battery backup. Image Credit: Xiaomi 2. Itel Color Pro 5G Price: ₹8,999/- Itel’s Color Pro 5G is one of the most affordable 5G smartphones in India. It’s powered by the MediaTek Dimensity 6080 (6nm) processor and runs on Android 13 (Itel OS 13). The device sports a 6.56-inch 90Hz IPS LCD display, making scrolling and gaming smoother. It includes 128GB storage and 6GB RAM, ensuring decent multitasking. The 50MP rear camera and 8MP front camera perform well in daylight conditions. With a 5000mAh battery and 18W fast charging, you can enjoy long hours of usage. Colors: River Blue, Lavender Fantasy Highlight: The most budget-friendly 5G phone with balanced specs. Image Credit: itel India 3. Samsung Galaxy M06 5G Price: ₹9,499/- The Samsung Galaxy M06 5G brings Samsung’s reliability and user-friendly One UI to the under ₹10K segment. It’s powered by an octa-core processor (2.4GHz + 2GHz) and offers a 6.7-inch HD+ PLS LCD display. With 6GB RAM and 128GB storage (expandable up to 1.5TB), it’s ideal for multitasking and storing media. The phone includes a 50MP + 2MP rear camera setup and 8MP front camera for selfies. Its 5000mAh battery supports all-day use, and Samsung’s optimization ensures efficient power management. Highlight: Trusted brand with long battery life and premium software experience. Image Credit: Samsung 4. Infinix Hot 50 5G Price: ₹9,999/- The Infinix Hot 50 5G offers excellent value with its 6.7-inch IPS LCD 90Hz display and MediaTek Dimensity 6300 chipset. Running on Android 14 with XOS 14, it delivers the latest software experience. The device features 8GB RAM and 128GB storage (expandable up to 1TB), along with a 48MP main camera and 8MP selfie camera. The 5000mAh battery with 18W fast charging provides excellent endurance, while the IP54 rating ensures dust and water resistance. Highlight: Latest Android version with durable, sleek design. Image Credit: Infinix 5. Vivo Y28 5G Price: Around ₹9,999/- The Vivo Y28 5G combines elegant looks with powerful performance. It features a 6.56-inch 90Hz IPS LCD display and runs on Android 13 (Funtouch OS 13). Powered by the MediaTek Dimensity 6020 (7nm) chipset, it offers smooth multitasking. The phone boasts a 50MP dual rear camera, 8MP selfie camera, and a 5000mAh battery with 15W charging. With up to 8GB RAM and 128GB storage, it’s a great all-rounder for this price segment. Colors: Crystal Purple, Glitter Aqua Highlight: Stylish design with balanced performance and great battery life. Image Credit: Vivo With so many options available under ₹10,000, choosing a smartphone with a 5000mAh battery and 5G support has never been easier. Whether you prioritise performance, display quality, or brand reliability, these top 5 picks for 2025 offer excellent value for money. Pick the one that suits your needs and enjoy long-lasting battery life, smooth multitasking, and vibrant visuals without stretching your budget. Upgrade smartly and make the most of your mobile experience this year!
Algorithm Showdown: Logistic Regression vs. Random Forest vs. XGBoost on Imbalanced Data
Algorithm Showdown: Logistic Regression vs. Random Forest vs. XGBoost on Imbalanced Data – MachineLearningMastery.com Algorithm Showdown: Logistic Regression vs. Random Forest vs. XGBoost on Imbalanced Data – MachineLearningMastery.com
iQOO 15 Launched With World’s First 2K LEAD OLED Display Technology; Check Display, Camera, Battery, Price And More | Technology News
iQOO 15 Launch And Price: iQOO has launched its flagship iQOO 15 smartphone in China. It comes with a powerful Snapdragon processor, several upgrades over the iQOO 13, and subtle design refinements. The company has also confirmed that the iQOO 15 will launch in India next month. Notably, the phone will run on OriginOS 6, replacing the long-standing Funtouch OS found in global variants of iQOO smartphones. The iQOO 15 debuts the world’s first 2K LEAD OLED display technology, which promises lower power consumption, higher brightness, enhanced eco-friendliness, and a slimmer profile. Adding further, it introduces the world’s first Pleasing Eye Protection 2.0, offering a non-polarized natural light display and hardware-level eye protection for gaming. The phone is offered in four colour options: iQOO 15 Lingyun, Legendary Edition, Track Edition, and Wilderness. Add Zee News as a Preferred Source iQOO 15 Specifications The phone features a stunning 6.85-inch 2K+ curved Samsung M14 8T LTPO AMOLED display with HDR10+ certification and a 144Hz refresh rate, delivering an ultra-smooth and vibrant viewing experience. It is powered by the latest Qualcomm Snapdragon 8 Elite Gen 5 processor paired with the Adreno 840 GPU, ensuring top-tier performance. The phone supports 12GB or 16GB of LPDDR5x RAM and 256GB, 512GB, or 1TB of UFS 4.1 storage, offering both speed and ample space for users. The smartphone houses a 7,000mAh battery with 100W wired fast charging (down from 120W on its predecessor) and 40W wireless charging support. (Also Read: Apple Eyes $4 Trillion Market Valuation Amid Robust iPhone 17 Series Sales) On the photography front, the iQOO 15 sports a triple rear camera setup comprising a 50MP primary sensor with OIS, a 50MP ultra-wide-angle lens, and a 50MP 3x periscope telephoto lens with OIS, while the front houses a 32MP camera for selfies and video calls. Adding further, it comes with an IP68/IP69 water and dust resistance rating, allowing it to withstand submersion up to 1.5 meters and resist cold or hot water jets from any direction. iQOO 15 Price The iQOO 15 starts at 4,199 yuan (Rs 51,900) for the 12GB RAM + 256GB storage model. The 16GB RAM + 512GB version is priced at 4,499 yuan (Rs 55,500), while the 12GB RAM + 512GB variant costs 4,699 yuan (Rs 58,000). The 16GB RAM + 512GB option is available for 4,999 yuan (Rs 61,700), and the top-end 16GB RAM + 1TB storage model is priced at 4,399 yuan (Rs 54,300).
7 Python Decorator Tricks to Write Cleaner Code
7 Python Decorator Tricks to Write Cleaner CodeImage by Editor Introduction Usually shrouded in mystery at first glance, Python decorators are, at their core, functions wrapped around other functions to provide extra functionality without altering the key logic in the function being “decorated”. Their main added value is keeping the code clean, readable, and concise, helping also make it more reusable. This article lists seven decorator tricks that can help you write cleaner code. Some of the examples shown are a perfect fit for using them in data science and data analysis workflows. 1. Clean Timing with @timer Ever felt you are cluttering your code by placing time() calls here and there to measure how long some heavy processes in your code take, like training a machine learning model or conducting large data aggregations? The @timer decorator can be a cleaner alternative, as shown in this example, in which you can replace the commented line of code inside the simulated_training decorated function with the instructions needed to train a machine learning model of your choice, and see how the decorator accurately counts the time taken to execute the function: import time from functools import wraps def timer(func): @wraps(func) def wrapper(*args, **kwargs): start = time.time() result = func(*args, **kwargs) print(f”{func.__name__} took {time.time() – start:.3f}s”) return result return wrapper @timer def simulated_training(): time.sleep(2) # pretend training a machine learning model here return “model trained” simulated_training() 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 import time from functools import wraps def timer(func): @wraps(func) def wrapper(*args, **kwargs): start = time.time() result = func(*args, **kwargs) print(f“{func.__name__} took {time.time() – start:.3f}s”) return result return wrapper @timer def simulated_training(): time.sleep(2) # pretend training a machine learning model here return “model trained” simulated_training() The key behind this trick is, of course, the definition of the wrapper() function inside timer(func). The majority of examples that follow will use this key pattern: first, we define the key function that can later be used as a decorator for another function. 2. Easier Debugging with @log_calls This is a very handy decorator for debugging purposes. It makes the process of identifying causes for errors or inconsistencies easier, by tracking which functions are called throughout your workflow and which arguments are being passed. A great way to save a bunch of print() statements everywhere! from functools import wraps import pandas as pd def log_calls(func): @wraps(func) def wrapper(*args, **kwargs): print(f”Calling {func.__name__} with {args}, {kwargs}”) return func(*args, **kwargs) return wrapper @log_calls def preprocess_data(df, scale=False): if not isinstance(df, pd.DataFrame): raise TypeError(“Input must be a pandas DataFrame”) return df.copy() # Simple dataset (Pandas DataFrame object) to demonstrate the function data = {‘col1’: [1, 2], ‘col2’: [3, 4]} sample_df = pd.DataFrame(data) preprocess_data(sample_df, scale=True) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 from functools import wraps import pandas as pd def log_calls(func): @wraps(func) def wrapper(*args, **kwargs): print(f“Calling {func.__name__} with {args}, {kwargs}”) return func(*args, **kwargs) return wrapper @log_calls def preprocess_data(df, scale=False): if not isinstance(df, pd.DataFrame): raise TypeError(“Input must be a pandas DataFrame”) return df.copy() # Simple dataset (Pandas DataFrame object) to demonstrate the function data = {‘col1’: [1, 2], ‘col2’: [3, 4]} sample_df = pd.DataFrame(data) preprocess_data(sample_df, scale=True) On first mention, remember to link important libraries for readers: for example, pandas. 3. Caching with @lru_cache This is a pre-defined Python decorator we can directly use by importing it from the functools library. It is suitable to wrap computationally expensive functions — from a recursive Fibonacci computation for a large number to fetching a large dataset — to avoid redundant computations. Useful if we have several heavy functions in computational terms and want to avoid manually implementing caching logic inside all of them one by one. LRU stands for “Least Recently Used”, i.e., a common caching strategy in Python. See also the functools docs. from functools import lru_cache @lru_cache(maxsize=None) def fibonacci(n): if n < 2: return n return fibonacci(n-1) + fibonacci(n-2) print(fibonacci(35)) # Caching this function call makes its execution much faster from functools import lru_cache @lru_cache(maxsize=None) def fibonacci(n): if n < 2: return n return fibonacci(n–1) + fibonacci(n–2) print(fibonacci(35)) # Caching this function call makes its execution much faster 4. Data Type Validations This decorator saves you from creating repetitive checks for clean data inputs or inputs belonging to the right type. For instance, below we define a custom decorator called @validate_numeric that customizes the error to throw if the input checked is not from a numeric data type. As a result, validations are kept consistent across different functions and parts of the code, and they are elegantly isolated from the core logic, math, and computations: from functools import wraps def validate_numeric(func): @wraps(func) def wrapper(x): # Accept ints and floats but reject bools (which are a subclass of int). if isinstance(x, bool) or not isinstance(x, (int, float)): raise ValueError(“Input must be numeric”) return func(x) return wrapper @validate_numeric def square_root(x): return x ** 0.5 print(square_root(16)) from functools import wraps def validate_numeric(func): @wraps(func) def wrapper(x): # Accept ints and floats but reject bools (which are a subclass of int). if isinstance(x, bool) or not isinstance(x, (int, float)): raise ValueError(“Input must be numeric”) return func(x) return wrapper @validate_numeric def square_root(x): return x ** 0.5 print(square_root(16)) 5. Retry on Failure with @retry Sometimes, your code may need to interact with components or establish external connections to APIs, databases, etc. These connections may sometimes fail for several, out-of-control reasons, occasionally even at random. Retrying the process several times in some cases is the way to go and navigate the issue, and the following decorator can be used to apply this “retry on failure” strategy a specified number of times: again, without mixing it with the core logic of your functions. import time, random from functools import wraps def retry(times=3, delay=1): def decorator(func): @wraps(func) def wrapper(*args, **kwargs): last_exc = None
India Ranks Second Globally In Refurbished Smartphone Growth: Report | Technology News
New Delhi: India saw a 5 per cent year-on-year (YoY) increase in refurbished smartphone sales in H1CY25, marking the second-fastest growth globally, a report has said. Apple’s iPhones drove growth, with refurbished iPhone sales in India increasing by 19 per cent, fuelled by strong demand for premium models like the iPhone 13 and iPhone 14 series, according to the report from global market research firm Counterpoint Research. The report indicated that the ongoing premiumisation of the broader smartphone market is now extending to refurbished devices as well, supported by rising consumer awareness, stronger supply chains, and surging demand for high-end models. Africa led global growth with a 6 per cent increase, driven by strong iPhone demand, the report noted. Apple secured the second position in India’s refurbished market, as Samsung maintained the top spot, though experiencing a minor 1 per cent decline. Samsung’s lead was maintained by consistent demand for its Galaxy S22 and S23 models. Additionally, the Samsung Galaxy S22 and S21 were among the top-selling models in India, the report said. Add Zee News as a Preferred Source Southeast Asia’s pre-owned smartphone market also grew 5 per cent YoY in H1 2025, fueled by its large unorganised channels and steady inflow of used devices and components from China. Online platforms are driving the consumer-to-consumer (C2C) market, especially for refurbished smartphones. This growth is fuelled by increasing consumer trust, better supply chains, and the convenience of initiating negotiations and transactions digitally, the research firm said. Organised retailers in India are solidifying buyback initiatives in both online and offline markets by promoting flagship models as reliable and value-driven alternatives. Retailer-driven exchange programs, extended warranty offerings are also driving demand for newer refurbished devices. Apple’s iPhone exports totalled approximately $10 billion, accounting for over 75 per cent of shipments in the first half of the year.
10 Python One-Liners for Calling LLMs from Your Code
Image by Author Introduction You don’t always need a heavy wrapper, a big client class, or dozens of lines of boilerplate to call a large language model. Sometimes one well-crafted line of Python does all the work: send a prompt, receive a response. That kind of simplicity can speed up prototyping or embedding LLM calls inside scripts or pipelines without architectural overhead. In this article, you’ll see ten Python one-liners that call and interact with LLMs. We will cover: Each snippet comes with a brief explanation and a link to official documentation, so you can verify what’s happening under the hood. By the end, you’ll know not only how to drop in fast LLM calls but also understand when and why each pattern works. Setting Up Before dropping in the one-liners, there are a few things to prepare so they run smoothly: Install required packages (only once): pip install openai anthropic google-generativeai requests httpx pip install openai anthropic google–generativeai requests httpx Ensure your API keys are set in environment variables, never hard-coded in your scripts. For example: export OPENAI_API_KEY=”sk-…” export ANTHROPIC_API_KEY=”claude-yourkey” export GOOGLE_API_KEY=”your_google_key” export OPENAI_API_KEY=“sk-…” export ANTHROPIC_API_KEY=“claude-yourkey” export GOOGLE_API_KEY=“your_google_key” For local setups (Ollama, LM Studio, vLLM), you need the model server running locally and listening on the correct port (for instance, Ollama’s default REST API runs at http://localhost:11434). All one-liners assume you use the right model name and that the model is either accessible via cloud or locally. With that in place, you can paste each one-liner directly into your Python REPL or script and get a response, subject to quota or local resource limits. Hosted API One-Liners (Cloud Models) Hosted APIs are the easiest way to start using large language models. You don’t have to run a model locally or worry about GPU memory; just install the client library, set your API key, and send a prompt. These APIs are maintained by the model providers themselves, so they’re reliable, secure, and frequently updated. The following one-liners show how to call some of the most popular hosted models directly from Python. Each example sends a simple message to the model and prints the generated response. 1. OpenAI GPT Chat Completion OpenAI’s API gives access to GPT models like GPT-4o and GPT-4o-mini. The SDK handles everything from authentication to response parsing. from openai import OpenAI; print(OpenAI().chat.completions.create(model=”gpt-4o-mini”, messages=[{“role”:”user”,”content”:”Explain vector similarity”}]).choices[0].message.content) from openai import OpenAI; print(OpenAI().chat.completions.create(model=“gpt-4o-mini”, messages=[{“role”:“user”,“content”:“Explain vector similarity”}]).choices[0].message.content) What it does: It creates a client, sends a message to GPT-4o-mini, and prints the model’s reply. Why it works: The openai Python package wraps the REST API cleanly. You only need your OPENAI_API_KEY set as an environment variable. Documentation: OpenAI Chat Completions API 2. Anthropic Claude Anthropic’s Claude models (Claude 3, Claude 3.5 Sonnet, etc.) are known for their long context windows and detailed reasoning. Their Python SDK follows a similar chat-message format to OpenAI’s. from anthropic import Anthropic; print(Anthropic().messages.create(model=”claude-3-5-sonnet”, messages=[{“role”:”user”,”content”:”How does chain of thought prompting work?”}]).content[0].text) from anthropic import Anthropic; print(Anthropic().messages.create(model=“claude-3-5-sonnet”, messages=[{“role”:“user”,“content”:“How does chain of thought prompting work?”}]).content[0].text) What it does: Initializes the Claude client, sends a message, and prints the text of the first response block. Why it works: The .messages.create() method uses a standard message schema (role + content), returning structured output that’s easy to extract. Documentation: Anthropic Claude API Reference 3. Google Gemini Google’s Gemini API (via the google-generativeai library) makes it simple to call multimodal and text models with minimal setup. The key difference is that Gemini’s API treats every prompt as “content generation,” whether it’s text, code, or reasoning. import os, google.generativeai as genai; genai.configure(api_key=os.getenv(“GOOGLE_API_KEY”)); print(genai.GenerativeModel(“gemini-1.5-flash”).generate_content(“Describe retrieval-augmented generation”).text) import os, google.generativeai as genai; genai.configure(api_key=os.getenv(“GOOGLE_API_KEY”)); print(genai.GenerativeModel(“gemini-1.5-flash”).generate_content(“Describe retrieval-augmented generation”).text) What it does: Calls the Gemini 1.5 Flash model to describe retrieval-augmented generation (RAG) and prints the returned text. Why it works: GenerativeModel() sets the model name, and generate_content() handles the prompt/response flow. You just need your GOOGLE_API_KEY configured. Documentation: Google Gemini API Quickstart 4. Mistral AI (REST request) Mistral provides a simple chat-completions REST API. You send a list of messages and receive a structured JSON response in return. import requests, json; print(requests.post(“https://api.mistral.ai/v1/chat/completions”, headers={“Authorization”:”Bearer YOUR_MISTRAL_API_KEY”}, json={“model”:”mistral-tiny”,”messages”:[{“role”:”user”,”content”:”Define fine-tuning”}]}).json()[“choices”][0][“message”][“content”]) import requests, json; print(requests.post(“https://api.mistral.ai/v1/chat/completions”, headers={“Authorization”:“Bearer YOUR_MISTRAL_API_KEY”}, json={“model”:“mistral-tiny”,“messages”:[{“role”:“user”,“content”:“Define fine-tuning”}]}).json()[“choices”][0][“message”][“content”]) What it does: Posts a chat request to Mistral’s API and prints the assistant message. Why it works: The endpoint accepts an OpenAI-style messages array and returns choices -> message -> content.Check out the Mistral API reference and quickstart. 5. Hugging Face Inference API If you host a model or use a public one on Hugging Face, you can call it with a single POST. The text-generation task returns generated text in JSON. import requests; print(requests.post(“https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2”, headers={“Authorization”:”Bearer YOUR_HF_TOKEN”}, json={“inputs”:”Write a haiku about data”}).json()[0][“generated_text”]) import requests; print(requests.post(“https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2”, headers={“Authorization”:“Bearer YOUR_HF_TOKEN”}, json={“inputs”:“Write a haiku about data”}).json()[0][“generated_text”]) What it does: Sends a prompt to a hosted model on Hugging Face and prints the generated text. Why it works: The Inference API exposes task-specific endpoints; for text generation, it returns a list with generated_text.Documentation: Inference API and Text Generation task pages. Local Model One-Liners Running models on your machine gives you privacy and control. You avoid network latency and keep data local. The tradeoff is set up: you need the server running and a model pulled. The one-liners below assume you have already started the local service. 6. Ollama (Local Llama 3 or Mistral) Ollama exposes a simple REST API on localhost:11434. Use /api/generate for prompt-style generation or /api/chat for chat turns. import requests; print(requests.post(“http://localhost:11434/api/generate”, json={“model”:”llama3″,”prompt”:”What is vector search?”}).text) import requests; print(requests.post(“http://localhost:11434/api/generate”, json={“model”:“llama3”,“prompt”:“What is vector search?”}).text) What it does: Sends a generate request to your local Ollama server and prints the raw response text. Why it works: Ollama runs a local HTTP server with endpoints like /api/generate and /api/chat. You must have the app running and the model pulled first. See official API documentation. 7. LM Studio (OpenAI-Compatible Endpoint) LM Studio can serve local models behind OpenAI-style endpoints such as /v1/chat/completions. Start the server from the Developer tab, then call it like any OpenAI-compatible backend. import requests; print(requests.post(“http://localhost:1234/v1/chat/completions”, json={“model”:”phi-3″,”messages”:[{“role”:”user”,”content”:”Explain embeddings”}]}).json()[“choices”][0][“message”][“content”]) import requests; print(requests.post(“http://localhost:1234/v1/chat/completions”, json={“model”:“phi-3”,“messages”:[{“role”:“user”,“content”:“Explain embeddings”}]}).json()[“choices”][0][“message”][“content”]) What it
Amazon Web Services Faces Major Outage: ChatGPT, Alexa, Snapchat, And Online Game Among Affected Services | Technology News
Amazon Web Services Services Down: Amazon Web Services (AWS) faced a major outage on Monday, disrupting several online services worldwide, including AI tools, e-commerce platforms, popular websites, and online games. The outage affected access to Amazon’s virtual assistant Alexa, the social media app Snapchat, the online game Fortnite, the AI platform ChatGPT, as well as the Epic Games Store and Epic Online Services. Amazon Web Services, Inc., a subsidiary of Amazon, provides on-demand cloud computing platforms and APIs to individuals, businesses, and governments on a metered, pay-as-you-go basis. Amazon reported that it is “investigating increased error rates and latencies for multiple AWS services in the US-EAST-1 Region” and that multiple services are “impacted” by operational issues. Users on social media platform Reddit reported that the Alexa smart assistant is down and unable to respond to queries or complete requests. AWS’ cloud-hosted platforms such as Perplexity, Airtable, Canva, and the McDonald’s app were also affected, according to user reports. Add Zee News as a Preferred Source The cause of the outage hasn’t been confirmed, and it’s unclear when regular service will be restored. Perplexity CEO Aravind Srinivas informed on social media platform X, “Perplexity is down right now. The root cause is an AWS issue. We’re working on resolving it.” AWS outage knocks Amazon, ChatGPT, Alexa and dozens of apps offline. The AWS dashboard first reported issues affecting the US-EAST-1 Region at 3:11AM Eastern Time (ET). “We are actively engaged and working to both mitigate the issue and understand root cause. We will provide an update in 45 minutes, or sooner if we have additional information to share,” Amazon said. Later at 5:27 a.m. ET, Amazon reported “significant signs of recovery,” adding that “most requests should now be succeeding.” We continue to work through a backlog of queued requests, it said. AWS outages in the US-EAST-1 region had caused wide-spread disruptions in 2020, 2021, and 2023, leading to extended downtime for various sites and applications. (With IANS Inputs)