In [1]:
import os
os.listdir()
Out[1]:
['.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']
In [2]:
os.chdir("Documents/python_programs/Astronomy_Datasets")
os.listdir()
Out[2]:
['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']
In [3]:
from sklearn.linear_model import LinearRegression
In [4]:
import pandas as pd
import numpy as np
import seaborn as sns
In [5]:
l = LinearRegression(fit_intercept=True)
In [6]:
s = pd.read_csv('stars.csv')
s.columns
Out[6]:
Index(['Temperature (K)', 'Luminosity(L/Lo)', 'Radius(R/Ro)',
       'Absolute magnitude(Mv)', 'Star type', 'Star color', 'Spectral Class'],
      dtype='object')
In [9]:
sns.scatterplot(x='Temperature (K)' , y='Absolute magnitude(Mv)',data=s)
Out[9]:
<Axes: xlabel='Temperature (K)', ylabel='Absolute magnitude(Mv)'>
In [16]:
new = s[['Temperature (K)' ,'Absolute magnitude(Mv)']]
new = new.fillna(0)
In [17]:
X = np.array(new['Temperature (K)'])
In [18]:
y = np.array(new['Absolute magnitude(Mv)'])
In [19]:
X = X[:,np.newaxis]
In [20]:
l.fit(X,y)
Out[20]:
LinearRegression()
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
LinearRegression()
In [27]:
xline = np.linspace(5000,40000,35001)
In [28]:
xline
Out[28]:
array([ 5000.,  5001.,  5002., ..., 39998., 39999., 40000.])
In [30]:
yline = l.predict(xline[:,np.newaxis])
In [31]:
yline
Out[31]:
array([ 6.92980807,  6.92934469,  6.92888131, ..., -9.28755285,
       -9.28801623, -9.28847961])
In [34]:
import matplotlib.pyplot as plt
plt.figure()
plt.plot(xline,yline)
sns.scatterplot(x='Temperature (K)' , y='Absolute magnitude(Mv)',data=s)
Out[34]:
<Axes: xlabel='Temperature (K)', ylabel='Absolute magnitude(Mv)'>
In [ ]: