import os
os.listdir()
['.var', 'Untitled.ipynb', '.bashrc', '.ipython', 'gnome_test', 'Pictures', '.node_repl_history', '.local', 'Desktop', 'substackfile.png', 'switzerland.qgz', 'ai-test', '.ssh', 'gpt4all', '.jupyter', '.streamlit', 'package-lock.json', 'Arduino', 'snap', '.arduino15', '.keras', 'testlatex.tex', '.sqlite_history', 'Music', '.theano', '.ipynb_checkpoints', 'Downloads', '.python_history', '.java', '.lesshst', '.npm', '.gitconfig', '.profile', '.RData', '.conda', 'texput.log', 'Public', '.anaconda', 'cap_%d', 'anaconda3', 'node_modules', '.googleearth', 'Documents', '.mozilla', 'Euler_9.py', 'test.txt', 'testlatex.aux', '.condarc', '.astropy', '.bash_history', '.continuum', '.grass8', '.config', 'Videos', 'Templates', 'package.json', 'R', 'wang_eset.RData', '.Rhistory', '.bash_logout', '.pki', 'testlatex.log', '.zoom', '.cache', '.vscode', 'git', 'bottomly_eset.RData', '.sudo_as_admin_successful']
os.chdir("Documents/python_programs/Astronomy_Datasets")
os.listdir()
['sloan_survey.csv', 'Astronomy_Dataset_Sources', 'planets.csv', 's', 'tinkgineer-hyg-star-database-archive', 'satellites.csv', 'ssplanets.csv', 'stars.csv', 'archive(1).zip', 'Jupiters_Moons.csv', 'planetstats.csv']
from sklearn.linear_model import LinearRegression
import pandas as pd
import numpy as np
import seaborn as sns
l = LinearRegression(fit_intercept=True)
s = pd.read_csv('stars.csv')
s.columns
Index(['Temperature (K)', 'Luminosity(L/Lo)', 'Radius(R/Ro)',
'Absolute magnitude(Mv)', 'Star type', 'Star color', 'Spectral Class'],
dtype='object')
sns.scatterplot(x='Temperature (K)' , y='Absolute magnitude(Mv)',data=s)
<Axes: xlabel='Temperature (K)', ylabel='Absolute magnitude(Mv)'>
new = s[['Temperature (K)' ,'Absolute magnitude(Mv)']]
new = new.fillna(0)
X = np.array(new['Temperature (K)'])
y = np.array(new['Absolute magnitude(Mv)'])
X = X[:,np.newaxis]
l.fit(X,y)
LinearRegression()In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
LinearRegression()
xline = np.linspace(5000,40000,35001)
xline
array([ 5000., 5001., 5002., ..., 39998., 39999., 40000.])
yline = l.predict(xline[:,np.newaxis])
yline
array([ 6.92980807, 6.92934469, 6.92888131, ..., -9.28755285,
-9.28801623, -9.28847961])
import matplotlib.pyplot as plt
plt.figure()
plt.plot(xline,yline)
sns.scatterplot(x='Temperature (K)' , y='Absolute magnitude(Mv)',data=s)
<Axes: xlabel='Temperature (K)', ylabel='Absolute magnitude(Mv)'>