Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Function to calculate mean
- def calculate_mean(data):
- return sum(data) / len(data)
- # Function to calculate median
- def calculate_median(data):
- sorted_data = sorted(data)
- n = len(sorted_data)
- if n % 2 == 0:
- return (sorted_data[n // 2 - 1] + sorted_data[n // 2]) / 2
- else:
- return sorted_data[n // 2]
- # Function to calculate mode
- def calculate_mode(data):
- frequency = {}
- for value in data:
- frequency[value] = frequency.get(value, 0) + 1
- max_frequency = max(frequency.values())
- mode = [key for key, val in frequency.items() if val == max_frequency]
- return mode
- # User input for data
- data = []
- while True:
- value = input("Enter a number (or 'done' to finish): ")
- if value.lower() == 'done':
- break
- data.append(int(value))
- # Calculate mean
- mean = calculate_mean(data)
- print("Mean:", mean)
- # Calculate median
- median = calculate_median(data)
- print("Median:", median)
- # Calculate mode
- mode = calculate_mode(data)
- print("Mode:", mode)
- #Liner regression
- import numpy as np
- from sklearn.linear_model import LinearRegression
- years = np.array([[1], [2], [3], [4], [5]])
- speeds = np.array([30, 45, 45, 55, 65])
- model = LinearRegression()
- model.fit(years, speeds)
- x= 15
- predicted_speed = model.predict([[x]])
- print(f"Predicted speed after {x} years:", predicted_speed[0], "km/h")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement