From e91240746766951f2948ba63adee238af2438f0e Mon Sep 17 00:00:00 2001 From: prvn8yfxg <3038505845@qq.com> Date: Sun, 28 May 2023 19:16:54 +0800 Subject: [PATCH] =?UTF-8?q?Delete=20'20407120-=E6=9D=8E=E7=91=9E=E5=B3=B0-?= =?UTF-8?q?=E8=AE=A1=E7=A7=912001.html'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 20407120-李瑞峰-计科2001.html | 15576 --------------------------- 1 file changed, 15576 deletions(-) delete mode 100644 20407120-李瑞峰-计科2001.html diff --git a/20407120-李瑞峰-计科2001.html b/20407120-李瑞峰-计科2001.html deleted file mode 100644 index c9ec3b3..0000000 --- a/20407120-李瑞峰-计科2001.html +++ /dev/null @@ -1,15576 +0,0 @@ - - -
- - -# your code
-# 计算阶乘函数
-def factorial(n):
- if n == 0:
- return 1
- else:
- return n * factorial(n-1)
-
-# 计算和
-total = 0
-for i in range(1, 21):
- total += factorial(i)
-
-# 输出结果
-print(total)
-2561327494111820313 --
# your code
-s = [9, 7, 8, 3, 2, 1, 55, 6]
-
-# 元素个数
-count = len(s)
-print("元素个数:", count)
-
-# 最大数
-maximum = max(s)
-print("最大数:", maximum)
-
-# 最小数
-minimum = min(s)
-print("最小数:", minimum)
-
-# 添加元素10
-s.append(10)
-print("添加元素10后的列表:", s)
-
-# 删除元素55
-s.remove(55)
-print("删除元素55后的列表:", s)
-元素个数: 8 -最大数: 55 -最小数: 1 -添加元素10后的列表: [9, 7, 8, 3, 2, 1, 55, 6, 10] -删除元素55后的列表: [9, 7, 8, 3, 2, 1, 6, 10] --
TTTTTx
-TTTTxx
-TTTxxx
-TTxxxx
-Txxxxx
-
-# your code
-T = 'T'
-x = 'x'
-length = 6
-for i in range(1, length):
- print(T * (length - i) + x * i)
-TTTTTx -TTTTxx -TTTxxx -TTxxxx -Txxxxx --
# your code
-def add(x, y):
- return x + y
-def subtract(x, y):
- return x - y
-def multiply(x, y):
- return x * y
-def divide(x, y):
- return x / y
-print("在下列功能中选择:")
-print("1.加法 2.减法 3.乘法 4.除法")
-choice = input("请输入对应功能项的数字(1.2.3.4):")
-num1 = int(input("请输入第一个数字:"))
-num2 = int(input("请输入第二个数字:"))
-if choice == '1':
- print(num1,"+",num2,"=",add(num1,num2))
-elif choice == '2':
- print(num1,"-",num2,"=",subtract(num1,num2))
-elif choice == '3':
- print(num1,"*",num2,"=",multiply(num1,num2))
-elif choice == '4':
- print(num1,"/",num2,"=",divide(num1,num2))
-else:
- print("功能选择错误,只接受1-4的数字!")
-在下列功能中选择: -1.加法 2.减法 3.乘法 4.除法 -请输入对应功能项的数字(1.2.3.4):1 -请输入第一个数字:1000 -请输入第二个数字:200 -1000 + 200 = 1200 --
# your code
-class Student:
- def __init__(self, name, age, course):
- self.name = name
- self.age = age
- self.course = course
-
- def get_name(self):
- return str(self.name)
-
- def get_age(self):
- return int(self.age)
-
- def get_course(self):
- return max(self.course)
-
-# 创建学生对象并测试
-st = Student('zhangming', 20, [69, 88, 100])
-print("学生姓名:" + st.get_name())
-print("学生年龄:" + str(st.get_age()))
-print("最高分:" + str(st.get_course()))
-学生姓名:zhangming -学生年龄:20 -最高分:100 --
| X | -Y | -X | -Y | -
|---|---|---|---|
| -3.00 | -4 | -0.15 | -255 | -
| -2.50 | -12 | -0.75 | -170 | -
| -1.75 | -50 | -1.25 | -100 | -
| -1.15 | -120 | -1.85 | -20 | -
| -0.50 | -205 | -2.45 | -14 | -
# your code
-import matplotlib.pyplot as plt
-
-# 定义数据
-data = {
- '-3.00': 4,
- '-2.50': 12,
- '-1.75': 50,
- '-1.15': 120,
- '-0.50': 205,
- '0.15': 255,
- '0.75': 170,
- '1.25': 100,
- '1.85': 20,
- '2.45': 14
-}
-
-# 绘制柱状图
-fig, ax = plt.subplots()
-ax.bar(data.keys(), data.values())
-
-# 添加标题和标签
-ax.set_title('Data Bar Chart')
-ax.set_xlabel('X')
-ax.set_ylabel('Y')
-
-# 显示图形
-plt.show()
-注:训练集:测试集=8:2,随机种子采用你学号后两位,例如你学号后两位=01,则random_state=1,如果最后两位=34,则random_state=34。最终结果打印出各个回归的w和b系数即可。
-| 序号 | -X1 | -X2 | -X3 | -X4 | -Y | -
|---|---|---|---|---|---|
| 1 | -7 | -26 | -6 | -60 | -78.5 | -
| 2 | -1 | -29 | -15 | -52 | -74.3 | -
| 3 | -11 | -56 | -8 | -20 | -104.3 | -
| 4 | -11 | -31 | -8 | -47 | -87.6 | -
| 5 | -7 | -52 | -6 | -33 | -95.9 | -
| 6 | -11 | -55 | -9 | -22 | -109.2 | -
| 7 | -3 | -71 | -17 | -6 | -102.7 | -
| 8 | -1 | -31 | -22 | -44 | -72.5 | -
| 9 | -2 | -54 | -18 | -22 | -93.1 | -
| 10 | -21 | -47 | -4 | -26 | -115.9 | -
| 11 | -1 | -40 | -23 | -34 | -83.8 | -
| 12 | -11 | -66 | -9 | -12 | -113.3 | -
| 13 | -10 | -68 | -8 | -12 | -109.4 | -
# your code
-from sklearn import model_selection, linear_model
-import numpy as np
-from sklearn import datasets
-boston = datasets.load_boston()
-data = np.array(
- [
- [7, 26, 6, 60],
- [1., 29., 15., 52.],
- [11, 56, 8, 20],
- [11, 31, 8, 47],
- [ 7, 52, 6, 33],
- [11, 55, 9, 22],
- [ 3, 71, 17, 6],
- [1, 31, 22, 44],
- [2, 54, 18, 22],
- [21, 47, 4, 26],
- [1, 40, 23, 34],
- [11, 66, 9, 12],
- [10, 68, 8, 12]
- ]
-)
-target = np.array(
- [
- [78.5],
- [74.3],
- [104.3],
- [87.6],
- [95.9],
- [109.2],
- [102.7],
- [72.5],
- [93.1],
- [115.9],
- [83.8],
- [113.3],
- [109.4]
- ]
-)
-x_train, x_test, y_train, y_test = model_selection.train_test_split(
- data, target, test_size=0.2, random_state=20
-)
-lr = linear_model.LinearRegression()
-rr = linear_model.Ridge()
-la = linear_model.Lasso()
-models = [lr, rr, la]
-names = ['Linear', 'Ridge', 'Lasso']
-for model, name in zip(models, names):
- model.fit(x_train, y_train)
-print('线性回归系数w: %s,线性回归截距b: %.2f' %(lr.coef_, lr.intercept_))
-print('岭回归系数w: %s,岭回归截距b: %.2f' %(rr.coef_, rr.intercept_))
-print('Lasso回归系数w: %s,岭回归截距b: %.2f' %(la.coef_, la.intercept_))
-线性回归系数w: [[2.14178865 0.96131663 0.73154799 0.32080833]],线性回归截距b: 15.03 -岭回归系数w: [[1.7932357 0.64097931 0.38981714 0.0060821 ]],岭回归截距b: 46.58 -Lasso回归系数w: [ 1.37229061 0.27016971 -0. -0.35421916],岭回归截距b: 83.10 --
C:\Users\13946\anaconda3\lib\site-packages\sklearn\utils\deprecation.py:87: FutureWarning: Function load_boston is deprecated; `load_boston` is deprecated in 1.0 and will be removed in 1.2. - - The Boston housing prices dataset has an ethical problem. You can refer to - the documentation of this function for further details. - - The scikit-learn maintainers therefore strongly discourage the use of this - dataset unless the purpose of the code is to study and educate about - ethical issues in data science and machine learning. - - In this special case, you can fetch the dataset from the original - source:: - - import pandas as pd - import numpy as np - - - data_url = "http://lib.stat.cmu.edu/datasets/boston" - raw_df = pd.read_csv(data_url, sep="\s+", skiprows=22, header=None) - data = np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]]) - target = raw_df.values[1::2, 2] - - Alternative datasets include the California housing dataset (i.e. - :func:`~sklearn.datasets.fetch_california_housing`) and the Ames housing - dataset. You can load the datasets as follows:: - - from sklearn.datasets import fetch_california_housing - housing = fetch_california_housing() - - for the California housing dataset and:: - - from sklearn.datasets import fetch_openml - housing = fetch_openml(name="house_prices", as_frame=True) - - for the Ames housing dataset. - - warnings.warn(msg, category=FutureWarning) --
注:训练集:测试集=1:1,随机种子采用你学号后两位,例如你学号后两位=01,则random_state=1,如果最后两位=34,则random_state=34。最终结果输出你预测结果、实际结果以及模型得分三项。
-| 序号 | -年龄 | -收入 | -是否为学生 | -信誉 | -购买计算机 | -
|---|---|---|---|---|---|
| 1 | -<=30 | -高 | -否 | -中 | -否 | -
| 2 | -<=30 | -高 | -否 | -优 | -否 | -
| 3 | -31-40 | -高 | -否 | -中 | -是 | -
| 4 | ->40 | -中 | -否 | -中 | -是 | -
| 5 | ->40 | -低 | -是 | -中 | -是 | -
| 6 | ->40 | -低 | -是 | -优 | -否 | -
| 7 | -31-40 | -低 | -是 | -优 | -是 | -
| 8 | -<=30 | -中 | -否 | -中 | -否 | -
| 9 | -<=30 | -低 | -是 | -中 | -是 | -
| 10 | ->40 | -中 | -是 | -中 | -是 | -
| 11 | -<=30 | -中 | -是 | -优 | -是 | -
| 12 | -31-40 | -中 | -否 | -优 | -是 | -
| 13 | -31-40 | -高 | -是 | -中 | -是 | -
| 14 | ->40 | -中 | -否 | -优 | -否 | -
import numpy as np
-import pandas as pd
-from sklearn import metrics
-# 导入高斯朴素贝叶斯分类器
-from sklearn.naive_bayes import GaussianNB
-from sklearn.model_selection import train_test_split
-
-x = np.array(
- [
- [1, 3, 0, 1, 0],
- [1, 3, 0, 2, 1],
- [2, 3, 0, 2, 1],
- [3, 2, 0, 1, 1],
- [3, 1, 1, 1, 1],
- [3, 1, 1, 2, 0],
- [2, 1, 1, 2, 1],
- [1, 2, 0, 1, 0],
- [1, 1, 1, 1, 1],
- [3, 2, 1, 1, 1],
- [1, 2, 1, 2, 1],
- [2, 2, 0, 2, 1],
- [2, 3, 1, 1, 1],
- [3, 2, 0, 2, 0],
- ]
-)
-
-y = np.array(
- [
- 0,1,1,1,1,0,1,0,1,1,1,1,1,0
- ]
-)
-X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.5, random_state=20)
-# 使用高斯朴素贝叶斯进行计算
-clf = GaussianNB()
-clf.fit(X_train, y_train)
-# 评估
-y_predict = clf.predict(X_test)
-score_gnb = metrics.accuracy_score(y_predict,y_test)
-
-print('该用户是否购买计算机:',y_predict)
-print(y_test)
-print(score_gnb)
-该用户是否购买计算机: [1 1 1 1 1 0 1] -[0 1 1 1 0 0 1] -0.7142857142857143 --