For SVM
# Import necessary libraries
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score

# Load dataset (Iris)
data = load_iris()
X = data.data      # Features
y = data.target    # Labels

# Split data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Create SVM model
svm = SVC(kernel='linear')  # You can also use 'rbf', 'poly', or 'sigmoid'

# Train the model
svm.fit(X_train, y_train)

# Predict on test data
y_pred = svm.predict(X_test)

# Evaluate model
print("Accuracy:", accuracy_score(y_test, y_pred))

For simple Linear regression:
# Import libraries
from sklearn.linear_model import LinearRegression
import numpy as np

# Create empty lists for data
X = []
y = []

# Take number of data points
n = int(input("Enter number of data points: "))

# Take input values from user
for i in range(n):
    xi = float(input(f"Enter X value {i+1}: "))
    yi = float(input(f"Enter Y value {i+1}: "))
    X.append([xi])   # X should be 2D
    y.append(yi)

# Create and train model
model = LinearRegression()
model.fit(X, y)

# Display results
print("\nModel trained successfully!")
print(f"Slope (Coefficient): {model.coef_[0]}")
print(f"Intercept: {model.intercept_}")

# Predict for a new user input
new_x = float(input("\nEnter new X value to predict Y: "))
pred_y = model.predict([[new_x]])
print(f"Predicted Y value: {pred_y[0]}")
