当前位置:天才代写 > Python代写 > 问题集代写 Python代写 Python notebook代写 data代写

问题集代写 Python代写 Python notebook代写 data代写

2021-05-12 14:16 星期三 所属: Python代写 浏览:57


BUFN 650 – Problem Set 1

 问题集代写 Important: Please submit your homework using Canvas. Your submission needs to in- clude two files: a PDF (or Word) document

Due on Tuesday, November 26 at 11:59 pm

Important: Please submit your homework using Canvas. Your submission needs to in- clude two files: a PDF (or Word) document with all your responses AND a copy of your Python notebook (.ipynb Jupyter notebook file). To produce the latter, please click File Download .ipynb in Google Colab, then save and upload the file on Canvas.问题集代写

Each student has to submit his/her individual assignment and show all work. Legibly handwritten and scanned submissions are allowed, but they need to be submitted as a single document. Please do not submit photographs of pages in separate files.

重要提示:请使用“画布”提交作业。您的提交需要包括两个文件:一个包含所有回复的PDF(或Word)文档,以及一个Python笔记本的副本(.ipynb Jupyter笔记本文件)。要生成后者,请单击文件→在Google Colab中下载.ipynb,然后在Canvas上保存并上传文件。


Part I: Short-answer questions (80 points) 问题集代写

Please provide a concise answer for each of the questions below. Usually one or two short sentences should suffice. Do not write novels.

1.(12 points) For each of parts (a) through (d),

indicate whether we would generally expectthe performance of a flexible statistical learning method to be better or worse than an inflexible method. Justify your answer.问题集代写

(a)The sample size n is extremely large, and the number of predictors p is

(b)Thenumber of predictors p is extremely large, and the number of observations is small.问题集代写

(c)The relationship between the predictors and response is highlynon-linear.

(d)The variance of the error terms, i.e. σ2= var(ε), is extremely

2.(9points) Explain whether each scenario is a classification or regression problem, 问题集代写

and indicate whether we are most interested in inference or  Finally, provide n and p.

(a)We collect a set of data on the top 500 firms in the US. For each firm werecord profit, number of employees, industry and the CEO  We are interested in understanding which factors affect CEO salary.

(b)Weare considering launching a new product and wish to know whether it will be a success or a  We collect data on 20 similar products that were previously launched. For each product we have recorded whether it was a success or failure, price charged for the product, marketing budget, competition price, and ten other variables.问题集代写

(c)Weare interested in predicting the % change in the USD/Euro exchange rate in relation to the weekly changes in the world stock  Hence we collect weekly data for all of 2019. For each week we record the % change in the USD/Euro, the % change in the US market, the % change in the British market, and the % change in the German market.



(d)误差项的方差即σ2= var(ε)非常大。




3.(12points) I collect a set of data (n = 100 observations) containing a single predictor

and a quantitative  I then fit a linear regression model to the data, as well as a separate cubic regression, i.e.,问题集代写

Y = β0 + β1X + β2X2 + β3X3 + s.

(a)Supposethat the true relationship between X and Y is linear, e.

Y = β0 + β1X + s.

Consider the training residual sum of squares (RSS) for the linear regression, and also the training RSS for the cubic regression. Would we expect one to be lower than the other, would we expect them to be the same, or is there not enough information to tell? Justify your answer.

(b)Answer(a) using test rather than training 问题集代写

(c)Suppose that the true relationship between X and Y is not linear, but we don’t knowhow far it is from  Consider the training RSS for the linear regression, and also the training RSS for the cubic regression. Would we expect one to be lower than the other, would we expect them to be the same, or is there not enough information to tell? Justify your answer.

(d)Answer(c) using test rather than training

3.(12分)我收集了一组数据(n = 100个观察值),其中包含一个预测变量和一个定量响应。然后,我将线性回归模型拟合到数据,以及单独的三次回归,即

Y =β0+β1X+β2X2+β3X3+ s。


Y =β0+β1X+ s。


4.(6 points) Consider the k-foldcross-validation.问题集代写

(a)Briefly explain how k-fold cross-validation is

(b)Whatare the advantages and disadvantages of k-fold cross-validation relative to the validation set approach?问题集代写

5.(3points) Suppose that we use some statistical learning method to make a prediction for the response Y for a particular value of the predictor X. Carefully describe how we might estimate the standard deviation of our

6.(11points) We perform best subset,

forward stepwise, and backward stepwise selection on a single data  For each approach, we obtain p + 1 models, containing 0, 1, 2, …, p predictors. Explain your answers:问题集代写

(a)Which of the three models with k predictors has the smallest trainingRSS?

(b)Whichof the three models with k predictors has the smallest test RSS?

(c)True or False (no explanation necessary; 1 pointeach):

i.Thepredictors in the k-variable model identified by forward stepwise are a subset of the predictors in the (k + 1)-variable model identified by forward stepwise

ii.Thepredictors in the k-variable model identified by backward stepwise are a subset of the predictors in the (k + 1)-variable model identified by backward stepwise 问题集代写

iii.Thepredictors in the k-variable model identified by backward stepwise are a subset of the predictors in the (k + 1)-variable model identified by forward stepwise

iv.Thepredictors in the k-variable model identified by forward stepwise are a subset of the predictors in the (k + 1)-variable model identified by backward stepwise

v.Thepredictors in the k-variable model identified by best subset are a subset of the predictors in the (k +1)-variable model identified by best subset



6.(11分)我们在单个数据集上执行最佳子集,向前逐步选择和向后逐步选择。对于每种方法,我们获得p + 1个模型,其中包含0、1、2,…,p个预测变量。说明您的答案:
i。通过逐步逐步确定的k变量模型中的预测变量是通过逐步逐步选择确定的(k +1)变量模型中的预测变量的子集。
ii。通过向后逐步选择确定的k变量模型中的预测变量是通过向后逐步选择确定的(k +1)变量模型中的预测变量的子集。
iii。后向逐步确定的k变量模型中的预测变量是前向逐步选择确定的(k +1)变量模型中的预测变量的子集。
iv。k变量中的预测变量由正向逐步选择确定的模型是(k + 1)变量模型中由向后逐步选择确定的预测子的子集。
v。由最佳子集标识的k变量模型中的预测变量是由最佳子集选择标识的(k +1)变量模型中的预测变量的子集

7.(12points) The lasso, relative to least squares, is:问题集代写

(a)Moreflexible and hence will give improved prediction accuracy when its increase in bias is less than its decrease in

(b)Moreflexible and hence will give improved prediction accuracy when its increase in variance is less than its decrease in 问题集代写

(c)Lessflexible and hence will give improved prediction accuracy when its increase in bias is less than its decrease in

(d)Lessflexible and hence will give improved prediction accuracy when its increase in variance is less than its decrease in

8.(15 points) Suppose we estimate the regression coefficients in a linear regression model byminimizing

for a particular value of s. For parts (a) through (e), indicate which of i. through v. is correct. Justify your answer.

(a)As we increase s from 0, the training RSSwill:

i.Increaseinitially, and then eventually start decreasing in an inverted U 问题集代写

ii.Decrease initially, and then eventually start increasing in a U




(b)Repeat (a) for test

(c)Repeat (a) for

(d)Repeat (a) for (squared)

(e)Repeat (a) for the irreducible





Part II: Predict the number of applications received by colleges (120 points)问题集代写

This exercise relates to the College data set, which can be found in the file College. It contains a number of variables for 777 different universities and colleges in the US. The variables are

  • Private: Public/privateindicator
  • Apps:Number of applications received
  • Accept: Number of applicantsaccepted
  • Enroll: Number of new students enrolled
  • Top10perc:  New students from top10
  • Top25perc:  New students from top25
  • Undergrad: Number of full-timeundergraduates
  • Undergrad: Number of part-timeundergraduates 问题集代写
  • Outstate: Out-of-statetuition
  • Board: Room and boardcosts
  • Books: Estimated bookcosts
  • Personal: Estimated personalspending
  • PhD: Percent of faculty withD.s
  • Terminal: Percent of faculty with terminaldegree
  • F.Ratio: Student/facultyratio
  • alumni: Percent of alumni whodonate
  • Expend: Instructional expenditure perstudent
  • Rate: Graduationrate

Before reading the data into Python, it can be viewed in Excel or a text editor.


1.(20 points) Exploring thedata:问题集代写

(a)Use the read csv(’http://faculty.marshall.usc.edu/gareth-james/ISL/College.csv’)function to read the data into Python. Call the loaded data college. Look at the data using the college.head() function. You should notice that the first column

is just the name of each university. We don’t really want Python to treat this as data. However, it may be handy to have these names for later. Set is as an index by passing an index col=0 parameter to the read csv() call above. Alternatively, you may use the college.set index() command. In the future, you can extract college names using college.index.问题集代写

(b)Usethe describe() function to produce a numerical summary of the vari- ables in the data set.

(c)Import the seaborn package and alias it as sns. Use the pairplot()  function  toproduce a scatterplot matrix of the first five columns or variables of the data. Recall that you can reference the first five columns using college.iloc[,:5].

(d)Use the boxplot(x=college[’Private’], y=college[’Outstate’]) function to pro- duceside-by-side boxplots of Outstate versus Private (two plots side-by-side; one for each Yes/No value of Private).问题集代写

(e)Createa new qualitative variable, called Elite, by binning the Top10perc We are going to divide universities into two groups based on whether or not the proportion of students coming from the top 10% of their high school classes exceeds 50%.

Use the sum() function to see how many elite universities there are. Now use the

sns.boxplot() function to produce side-by-side boxplots of Outstate versus Elite. (f) Use the college.hist() function to produce some histograms for a few of the quan-

titative variables. You may find parameters bins=20,figsize=(15,10) useful.问题集代写

(g) Continue exploring the data, and provide a brief summary of what you discover.


(a)使用pd.read csv(’http://faculty.marshall.usc.edu/gareth-james/ISL/College.csv’)函数将数据读取到Python中。致电加载的数据学院。使用college.head()函数查看数据。您应该注意到第一列
只是每所大学的名字。我们真的不希望Python将其视为数据。但是,稍后使用这些名称可能会很方便。通过将index col = 0参数传递到上面的read csv()调用,将Set用作索引。或者,您可以使用college.set index()命令。将来,您可以使用college.index提取大学名称。
(c)导入seaborn软件包并将其别名为sns。使用sns.pairplot()函数生成前五列或数据变量的散点图矩阵。回想一下,您可以使用college.iloc [,:5]引用前五列。
(d)使用sns.boxplot(x = college [‘Private’],y = college [‘Outstate’])函数来制作Outstate与Private的并排箱线图(两个并排图;每个“专用”的“是/否”值各一个)。
sns.boxplot()函数可生成Outstate与Elite的并排Boxplot。 (f)使用college.hist()函数生成一些直方图,
称谓变量。您可能会发现bins = 20,figsize =(15,10)参数很有用。

2.(100 points) Now, let’s predict the number of applications received (variable Apps) using the other variables in the College dataset:问题集代写

(a)(5points) Replace any text variables with numeric  You may use

pd.get dummies(college, drop first=True) to achieve this.

(b)(5 points) Construct response y (Apps) and predictors X (the rest of variables). You are worried that non-linearities in X could be important and decide toadd

all second-order terms to your predictors (i.e., x1, x2, x1x2, x2, x2 etc.). Add these

terms to your X. Hint: you can use PolynomialFeatures().fit transform(X) func- tion from sklearn.preprocessing package. If you did everything correctly, the set of variables in X should now be expanded from 18 to 190 features (all second-order terms, including interactions and a vector of ones).

(c)(5 points) Split the data set into a training set and a test set. Never use the test setfor anything but reporting the test error when asked

(d)(5 points) Standardize all explanatory variables (subtract their time-series means and divide by standard deviation). Verify that all variables now have zeromean and unitary standard 问题集代写

(e)(10 points) Fit a linear model using least squares on the training set, and report the test error obtained. Warning: if you used PolynomialFeatures().fit transform(X) anda vector of ones was added to predictors, set fit intercept=False.

(f)(15 points) Fit a ridge regression model on the training set, with λ chosen by cross-validation. Cross-validation should be performed using only the training set portionof the data in (a). Plot cross-validated MSE as a function of λ. Plot paths of coefficients as a function of λ. Report the test error obtained. Hint: I showed how to perform many of these steps in class in the Chapter 6.ipynb 

(g)(15points) Repeat (f) using lasso

You will likely receive convergence warnings or experience slowness. Use the original characteristics (with no second- order terms) if you do. Report the number of non-zero coefficients.

(h)(15points) Repeat (f) using random  Recall that random forests and regres- sion trees allow for interactions and non-linearities in X by design. Therefore, use the original set of characteristics here (with no second-order terms). Experiment with the max depth parameter.问题集代写

(i)(15 points) Fit an elastic net model on the training set, with λ chosen by cross- validation.Use the original  Report the test error obtained. Hint: Use ElasticNetCV() estimator from sklearn.linear model to cross-validate and fit a model. You can read more here. Elastic net needs to cross-validate two param- eters. You can do this automatically by adding l1 ratio=np.linspace(.05,  1,  20) as a parameter.

(j)(10points) Comment on the results  How accurately can we predict the number of college applications received? Is there much difference among the test errors resulting from these five approaches?

pd.get假人(学院,首先掉落= True)来实现这一目标。

1 2
提示:可以使用sklearn.preprocessing包中的PolynomialFeatures()。fit transform(X)函数。如果您正确完成了所有操作,则X中的变量集现在应该从18个要素扩展到190个要素(所有二阶项,包括交互作用和矢量的项)。
(e)(10分)在训练集上使用最小二乘法拟合线性模型,并报告获得的测试误差。警告:如果您使用了PolynomialFeatures()。fit transform(X),并且向预测变量添加了1的向量,请设置fit拦截= False。
(i)(15分)在训练集上拟合一个弹性网模型,通过交叉验证选择λ。使用原始特征。报告获得的测试错误。提示:使用sklearn.linear模型中的ElasticNetCV()估计器对模型进行交叉验证和拟合。你可以在这里阅读更多。弹性网需要交叉验证两个参数。您可以通过添加l1 ratio = np.linspace(.05,1,20)作为参数来自动执行此操作。


其他代写:web代写 program代写 cs作业代写 analysis代写 app代写 essay代写 assembly代写 Haskell代写 homework代写 Programming代写 Task代写 考试助攻 web代写 finance代写 Exercise代写

合作平台:essay代写 论文代写 写手招聘 英国留学生代写