दो संख्यात्मक व्याख्यात्मक वैरिएबल्स

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

Maarten Van den Broeck

Content Developer at DataCamp

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

  • 3D स्कैटर प्लॉट
  • 2D स्कैटर प्लॉट, रिस्पॉन्स को रंग में दिखाएँ
इंटरमीडिएट Regression with statsmodels in Python

फिश डेटासेट के लिए एक और कॉलम

species mass_g length_cm height_cm
Bream 1000 33.5 18.96
Bream 925 36.2 18.75
Roach 290 24.0 8.88
Roach 390 29.5 9.48
Perch 1100 39.0 12.80
Perch 1000 40.2 12.60
Pike 1250 52.0 10.69
Pike 1650 59.0 10.81
इंटरमीडिएट Regression with statsmodels in Python

3D स्कैटर प्लॉट

सभी मछली प्रजातियों का 3D स्कैटर प्लॉट, जिसमें अक्षों पर length, mass और height हैं। 2D प्लेन में इस प्लॉट की व्याख्या करना कठिन है.

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

2D स्कैटर प्लॉट, रिस्पॉन्स के लिए रंग

sns.scatterplot(x="length_cm", 
                y="height_cm",
                data=fish,
                hue="mass_g")

2D स्कैटर प्लॉट, तीसरे संख्यात्मक वैरिएबल को दिखाने के लिए mass को रंग में दिखाया गया है.

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

दो संख्यात्मक व्याख्यात्मक वैरिएबल्स के साथ मॉडलिंग

mdl_mass_vs_both = ols("mass_g ~ length_cm + height_cm",
                       data=fish).fit()

print(mdl_mass_vs_both.params)
Intercept   -622.150234
length_cm     28.968405
height_cm     26.334804
इंटरमीडिएट Regression with statsmodels in Python

प्रेडिक्शन फ्लो

from itertools import product

length_cm = np.arange(5, 61, 5)
height_cm = np.arange(2, 21, 2)

p = product(length_cm, height_cm)

explanatory_data = pd.DataFrame(p,
                                columns=["length_cm",
                                         "height_cm"])
prediction_data = explanatory_data.assign(
  mass_g = mdl_mass_vs_both.predict(explanatory_data))
print(prediction_data)
     length_cm  height_cm       mass_g
0            5          2  -424.638603
1            5          4  -371.968995
2            5          6  -319.299387
3            5          8  -266.629780
4            5         10  -213.960172
..         ...        ...          ...
115         60         12  1431.971694
116         60         14  1484.641302
117         60         16  1537.310909
118         60         18  1589.980517
119         60         20  1642.650125

[120 rows x 3 columns]
इंटरमीडिएट Regression with statsmodels in Python

प्रेडिक्शंस प्लॉट करना

sns.scatterplot(x="length_cm",
                y="height_cm",
                data=fish,
                hue="mass_g")
sns.scatterplot(x="length_cm",
                y="height_cm",
                data=prediction_data,
                hue="mass_g",
                legend=False,
                marker="s")
plt.show()

मछलियों के length, height और mass का स्कैटर प्लॉट, प्रेडिक्शन ग्रिड सहित.

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

एक इंटरैक्शन शामिल करना

mdl_mass_vs_both_inter = ols("mass_g ~ length_cm * height_cm",
                             data=fish).fit()
print(mdl_mass_vs_both_inter.params)
Intercept              159.107480
length_cm                0.301426
height_cm              -78.125178
length_cm:height_cm      3.545435
इंटरमीडिएट Regression with statsmodels in Python

इंटरैक्शन के साथ प्रेडिक्शन फ्लो

length_cm = np.arange(5, 61, 5)
height_cm = np.arange(2, 21, 2)

p = product(length_cm, height_cm)

explanatory_data = pd.DataFrame(p,
                                columns=["length_cm",
                                         "height_cm"])

prediction_data = explanatory_data.assign(
  mass_g = mdl_mass_vs_both_inter.predict(explanatory_data))
इंटरमीडिएट Regression with statsmodels in Python

प्रेडिक्शंस प्लॉट करना

sns.scatterplot(x="length_cm",
           y="height_cm",
           data=fish,
           hue="mass_g")

sns.scatterplot(x="length_cm",
                y="height_cm",
                data=prediction_data,
                hue="mass_g",
                legend=False,
                marker="s")
plt.show()

मछलियों के length, height और mass का स्कैटर प्लॉट, प्रेडिक्शन ग्रिड पर इंटरैक्शन टर्म सहित.

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

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

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

Preparing Video For Download...