-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualization_practice.py
More file actions
69 lines (51 loc) · 1.82 KB
/
visualization_practice.py
File metadata and controls
69 lines (51 loc) · 1.82 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures
full_data = pd.read_csv("Stars.csv")
# Plotting the distribution of the 'Type' variable
"""plt.figure(figsize=(8, 5))
full_data['Type'].value_counts().plot(kind='bar', color = ['blue', 'orange', 'green', 'red', 'purple', 'cyan', 'magenta'])
print("Value counts for 'Type':\n", full_data['Type'].value_counts())
plt.title('Distribution of Star Types')
plt.xlabel('Star Type')
plt.ylabel('Count')
plt.xticks(rotation=0)
plt.show()"""
# Relationship between Spectral Class and Star Type
"""
plt.figure(figsize=(10, 6))
pd.crosstab(full_data['Spectral_Class'], full_data['Type']).plot(kind='bar', stacked=True, colormap='viridis')
plt.title('Spectral Class vs Star Type')
plt.xlabel('Spectral Class')
plt.ylabel('Count')
plt.xticks(rotation=0)
plt.legend(title='Star Type')
plt.show()
"""
#sort x and y by temperature
sorted_indices = np.argsort(full_data['Temperature'].values)
full_data = full_data.iloc[sorted_indices]
#Relatinship between temperature and star type
x = full_data['Temperature'].values.reshape(-1, 1)
print("Temperature shape:", x.shape)
y = full_data['A_M']
poly = PolynomialFeatures(degree=2)
x_poly = poly.fit_transform(x)
print("Polynomial features (first 5 rows):\n", x_poly[:5])
print("Polynomial features shape:", x_poly.shape)
print("A_M shape:", y.shape)
model = LinearRegression()
model.fit(x_poly, y)
pred = model.predict(x_poly)
print("Predicted A_M shape:", pred.shape)
print("Predicted A_M:", pred)
plt.figure(figsize=(10, 6))
plt.scatter(x, y, color='blue', label='Data Points')
plt.plot(x, pred, color='red', label='Linear Fit')
plt.title('Temperature vs Star Type')
plt.xlabel('Temperature')
plt.ylabel('Star Type')
plt.legend()
plt.show()