现有数据集Advertising.csv。数据集包含了200个不同市场的产品销售额,每个销售额对应3种广告媒体投入成本,分别是:TV, radio, 和 newspaper。如果我们能分析出广告媒体投入与销售额之间的关系,我们就可以更好地分配广告开支并且使销售额最大化。
现需要进行如下实验:
1、使用pandas库读取数据集,得到相应矩阵。使用matplotlib库画出:TV、Radio、Newspaper与产品销售额的数据散点图。
具体要求:
- 结果为一张图,TV, radio, 和 newspaper需要用不同形状的点表示。
- 图的X轴为广告花费、Y轴为销售额的值。
- 需要画出虚线形式的网格参考线。
def graph1( data ):
TV = data.TV
Radio = data.Radio
Newspaper = data.Newspaper
Sales = data.Sales
plt.scatter(TV, Sales, c='r',marker='o',label='TV')
plt.scatter(Radio, Sales, c='b', marker='x', label='Radio')
plt.scatter(Newspaper, Sales, c='y', marker='d', label='Newspaper')
plt.legend()
plt.ylabel("销售额",fontproperties=zhfont1)
plt.xlabel('广告花费',fontproperties=zhfont1)
plt.grid(linestyle='-.')
plt.savefig('D://Ml_lab_result/ProblemA_1.png')