ESE begin 27 April 2026. View Timetable
Logo

Colab Code

Run ML code in Google Colab

Run the following code in Google Colab to test your ML models.


Cell 1: Linear Regression

import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression

X = [[1],[2],[3],[4]]
y = [2,4,6,8]

model = LinearRegression().fit(X, y)

# input array
X_new = [2, 4, 6, 8]

# convert to 2D (column vector)
X_new = np.array(X_new).reshape(-1, 1)

print("Predictions:", model.predict(X_new))

Cell 2: Logistic Regression

import numpy as np
from sklearn.linear_model import LogisticRegression

# Sample dataset
X = [[1], [2], [3], [4]]
y = [0, 0, 1, 1]

# Train model
model = LogisticRegression().fit(X, y)

# Multiple inputs
X_new = [1, 2, 3, 4, 5]

# Convert to 2D
X_new = np.array(X_new).reshape(-1, 1)

# Predictions
predictions = model.predict(X_new)
probabilities = model.predict_proba(X_new)

print("Predictions:", predictions)
print("Probabilities:\n", probabilities)
ColabOpen Colab

On this page