首页 > 其他分享 >Machine Learning - A Forest of Trees

Machine Learning - A Forest of Trees

时间:2024-02-21 14:12:01浏览次数:25  
标签:random Trees Machine state train Forest test split

Build a Random Forest model.

Task
You will be given a feature matrix X and target array y. Your task is to split the data into training and test sets, build a Random Forest model with the training set, and make predictions for the test set. Give the random forest 5 trees.

You will be given an integer to be used as the random state. Make sure to use it in both the train test split and the Random Forest model.

Input Format
First line: integer (random state to use)
Second line: integer (number of datapoints)
Next n lines: Values of the row in the feature matrix, separated by spaces
Last line: Target values separated by spaces

Output Format
Numpy array of 1's and 0's

Sample Input
1
10
-1.53 -2.86
-4.42 0.71
-1.55 1.04
-0.6 -2.01
-3.43 1.5
1.45 -1.15
-1.6 -1.52
0.79 0.55
1.37 -0.23
1.23 1.72
0 1 1 0 1 0 0 1 0 1

Sample Output
[1 0 0]

 

Explanation
The train test split puts these three points into the test set:
[-1.55 1.04], [1.23 1.72], [-1.6 -1.52]. The true values for these points are [1 1 0] and the model correctly predicts [1 1 0].

==================================================

import numpy as np from sklearn.model_selection import train_test_split from sklearn.ensemble import RandomForestClassifier
random_state = int(input()) n = int(input()) rows = [] for i in range(n):     rows.append([float(a) for a in input().split()])
X = np.array(rows) y = np.array([int(a) for a in input().split()])
X_train, X_test, y_train, y_test = train_test_split(X, y,random_state=random_state) rf = RandomForestClassifier(n_estimators=5,random_state=random_state) rf.fit(X_train, y_train) print(rf.predict(X_test))  

标签:random,Trees,Machine,state,train,Forest,test,split
From: https://www.cnblogs.com/tinghae/p/18025076

相关文章

  • Java集合篇之set,面试官:请说一说HashSet、LinkedHashSet、TreeSet的区别?
    写在开头Java的集合世界中主要由List,Set,Queue,Map构成,我们在之前的博文中已经学习了List,接下来我们继续学习Set集合。Set特点:存取无序,不可以存放重复的元素,不可以用下标对元素进行操作HashSet作为Set容器的代表子类,HashSet经常被用到,我们通过源码去分析它【源码查看】public......
  • 迎龙年浅谈 Binary Indexed Trees
    什么是BinaryIndexedTrees?就是树状数组啦。树状数组,是一种高级数据结构,用于高效地解决某一类问题。那么这一类问题是什么呢?那么让我们一起来看一下:问题引入给定一个序列\(a\),给定\(Q\)个\(l,r\),求\(\sum_{i=l}^ra_i\)。这一类问题,我们明显可以暴力枚举,时间复杂度为......
  • Mechanism of Machine Learning
    1.WhatisMachineLearning?MachineLearning=StatisticLearning,namely,thereisanunknowndistributionof(x1,x2,...,xm,y),thetaskistoinferywhen(x1,x2,...,xm)isknown,Althoughthedistributionisunknown,sotherelationbetween(x1,......
  • Java 中的属性类Properties 以及TreeSet和TreeMap
    属性类Propertiesimportjava.util.Properties;/**目前只需要掌握Properties属性类对象的相关方法即可*Properties是一个Map集合,继承Hashtable,Properties的key和value都是String类型*Properties被称为属性类对象*Properties是线程安全的**/publicclassProperties......
  • Java 中的HashSet 和 TreeSet
    HashSetHashSet集合:无序不可重复方法HashSet集合的元素实际上是放到HashMap集合的Key中importjava.util.HashSet;importjava.util.Set;/**HashSet集合:无序不可重复**/publicclassHashSetTest{publicstaticvoidmain(String[]args){//演示一......
  • EasyCVR智能边缘网关启动失败报错“Local Machine Check Error”的解决方法
    国标GB28181安防监控系统EasyCVR平台采用了开放式的网络结构,可支持4G、5G、WiFi、有线等方式进行视频的接入与传输、处理和分发。安防视频监控平台EasyCVR还能支持GIS电子地图模式,基于监控摄像头的经纬度地理位置信息,将场景中的整体安防布控以可视化地图方式呈现,管理人员可以方便......
  • EasyCVR启动失败报错“Local Machine Check Error”的解决方法
    有用户反馈EasyCVR智能边缘网关启动失败,导致服务无法使用,今天我们来分析一下问题的排查与解决方法。1)查看报错日志,如下:2)报错为“LocalMachineCheckError!本地机器检查错误!”,检查配置文件是否因为hardware_version字段影响了服务启动;3)将该字段参数进行注释,然后再次启动EasyCVR查看......
  • ML系列-《The Hundred-Page Machine Learning book》-读书
    Abouttheauthor:作者简介安德烈·布可夫(AndriyBurkov)是一位机器学习专家,目前居住于加拿大魁北克省。他拥有人工智能博士学位,尤其擅长自然语言处理技术。目前,他是高德纳(Gartner)咨询公司机器学习开发团队的主管。该团队的主要工作是,使用浅层和深度学习技术,开发可用于生产环境......
  • compareTo、Comparator、TreeSet排序那些事
    前言:对于后端开发而言,学会对数据的自定义排序还是十分有必要的。需要用到排序的场景也是很多的,什么排行版展示、利用时间+别的条件排序、还有预接单的数据就是要展示在已接单的数据前面这种需求、等等。总之很重要的!一:对集合排序对以下的数据做展示顺序排序:未接单>预接单>已接单。(......
  • 解决 Ant TreeSelect(树选择)组件可以使用键盘选中 disabled(已禁用)项的问题
    最近在使用AntDesignVue(V3.2.20)的TreeSelect组件时发现一个问题:tree-data中部分数据的disabled属性设置为了true,选项是“禁用”状态,无法通过鼠标点击选中,但是可以通过键盘↑↓键切换选项,按下Enter键选中。一开始还以为是bug,后来通过查阅文档和测试发现,该组件还......