पैरेलल स्लोप्स लीनियर रिग्रेशन

इंटरमीडिएट Regression with statsmodels in Python

Maarten Van den Broeck

Content Developer at DataCamp

पिछला कोर्स

यह कोर्स Introduction to Regression with statsmodels in Python का ज्ञान मानकर चलता है

इंटरमीडिएट Regression with statsmodels in Python

सिंपल से मल्टिपल रिग्रेशन तक

मल्टिपल रिग्रेशन वह रिग्रेशन मॉडल है जिसमें एक से अधिक explanatory वैरिएबल होते हैं।

ज्यादा explanatory वैरिएबल से बेहतर समझ और बेहतर प्रेडिक्शन मिलते हैं।

इंटरमीडिएट Regression with statsmodels in Python

कोर्स कंटेंट

अध्याय 1

  • "पैरेलल स्लोप्स" रिग्रेशन

अध्याय 2

  • इंटरैक्शन
  • सिम्पसन का पैरेडॉक्स

अध्याय 3

  • और explanatory वैरिएबल
  • लीनियर रिग्रेशन कैसे काम करता है

अध्याय 4

  • मल्टिपल लॉजिस्टिक रिग्रेशन
  • लॉजिस्टिक डिस्ट्रीब्यूशन
  • लॉजिस्टिक रिग्रेशन कैसे काम करता है
इंटरमीडिएट Regression with statsmodels in Python

Fish डेटासेट

mass_g length_cm species
242.0 23.2 Bream
5.9 7.5 Perch
200.0 30.0 Pike
40.0 12.9 Roach
  • हर पंक्ति एक मछली दर्शाती है
  • mass_g response वैरिएबल है
  • 1 संख्यात्मक, 1 श्रेणीबद्ध explanatory वैरिएबल
इंटरमीडिएट Regression with statsmodels in Python

एक समय में एक explanatory वैरिएबल

from statsmodels.formula.api import ols

mdl_mass_vs_length = ols("mass_g ~ length_cm",
                         data=fish).fit()
print(mdl_mass_vs_length.params)
Intercept   -536.223947
length_cm     34.899245
dtype: float64
  • 1 इंटरसेप्ट कोएफिशिएंट
  • 1 स्लोप कोएफिशिएंट
mdl_mass_vs_species = ols("mass_g ~ species + 0",
                          data=fish).fit()

print(mdl_mass_vs_species.params)
species[Bream]    617.828571
species[Perch]    382.239286
species[Pike]     718.705882
species[Roach]    152.050000
dtype: float64
  • हर श्रेणी के लिए 1 इंटरसेप्ट कोएफिशिएंट
इंटरमीडिएट Regression with statsmodels in Python

दोनों वैरिएबल साथ में

mdl_mass_vs_both = ols("mass_g ~ length_cm + species + 0",
                       data=fish).fit()
print(mdl_mass_vs_both.params)
species[Bream]    -672.241866
species[Perch]    -713.292859
species[Pike]    -1089.456053
species[Roach]    -726.777799
length_cm           42.568554
dtype: float64
  • 1 स्लोप कोएफिशिएंट
  • हर श्रेणी के लिए 1 इंटरसेप्ट कोएफिशिएंट
इंटरमीडिएट Regression with statsmodels in Python

कोएफिशिएंट्स की तुलना

print(mdl_mass_vs_length.params)
Intercept   -536.223947
length_cm     34.899245
print(mdl_mass_vs_both.params)
species[Bream]    -672.241866
species[Perch]    -713.292859
species[Pike]    -1089.456053
species[Roach]    -726.777799
length_cm           42.568554
print(mdl_mass_vs_species.params)
species[Bream]    617.828571
species[Perch]    382.239286
species[Pike]     718.705882
species[Roach]    152.050000
इंटरमीडिएट Regression with statsmodels in Python

विज़ुअलाइज़ेशन: 1 संख्यात्मक explanatory वैरिएबल

import matplotlib.pyplot as plt
import seaborn as sns

sns.regplot(x="length_cm",
            y="mass_g",
            data=fish,
            ci=None)

plt.show()

मछली का mass बनाम length का स्कैटर प्लॉट, साथ में लीनियर ट्रेंड लाइन

इंटरमीडिएट Regression with statsmodels in Python

विज़ुअलाइज़ेशन: 1 श्रेणीबद्ध explanatory वैरिएबल

sns.boxplot(x="species",
            y="mass_g",
            data=fish,
            showmeans=True)

हर species के लिए मछली के mass का बॉक्सप्लॉट

इंटरमीडिएट Regression with statsmodels in Python

विज़ुअलाइज़ेशन: दोनों explanatory वैरिएबल

coeffs = mdl_mass_vs_both.params
print(coeffs)
species[Bream]    -672.241866
species[Perch]    -713.292859
species[Pike]    -1089.456053
species[Roach]    -726.777799
length_cm           42.568554
ic_bream, ic_perch, ic_pike, ic_roach, sl = coeffs
sns.scatterplot(x="length_cm",
                y="mass_g",
                hue="species",
                data=fish)
plt.axline(xy1=(0, ic_bream), slope=sl, color="blue")
plt.axline(xy1=(0, ic_perch), slope=sl, color="green")
plt.axline(xy1=(0, ic_pike), slope=sl, color="red")
plt.axline(xy1=(0, ic_roach), slope=sl, color="orange")

species के अनुसार वर्गीकृत, fish mass बनाम length के पैरेलल स्लोप्स मॉडल

इंटरमीडिएट Regression with statsmodels in Python

अभ्यास करते हैं!

इंटरमीडिएट Regression with statsmodels in Python

Preparing Video For Download...