我正在使用Python中的scikit learn构建决策树.我已经在特定数据集上训练了模型,现在我想保存这个决策树,以便以后可以使用它(在新数据集上).任何人都知道如何做到这一点.
我正在 PySpark 中使用机器学习并使用 RandomForestClassifier。到目前为止,我一直在使用 Sklearn。我正在使用 CrossValidator 来调整参数并获得最佳模型。下面是来自 Spark 网站的示例代码。
从我读过的内容来看,我不明白 spark 是否也分配了参数调整,还是与 Sklearn 的 GridSearchCV 的情况相同。
任何帮助将不胜感激。
from pyspark.ml import Pipeline
from pyspark.ml.classification import LogisticRegression
from pyspark.ml.evaluation import BinaryClassificationEvaluator
from pyspark.ml.feature import HashingTF, Tokenizer
from pyspark.ml.tuning import CrossValidator, ParamGridBuilder
# Prepare training documents, which are labeled.
training = spark.createDataFrame([
    (0, "a b c d e spark", 1.0),
    (1, "b d", 0.0),
    (2, "spark f g h", 1.0),
    (3, "hadoop mapreduce", 0.0),
    (4, "b spark who", 1.0),
    (5, "g d a …Run Code Online (Sandbox Code Playgroud) 我收到此错误:
Error in x$getinverse : $ operator is invalid for atomic vectors
Run Code Online (Sandbox Code Playgroud)
我的代码是这个。我不明白我在哪里犯错。
##create a function which starts with a null matrix argument
makeCacheMatrix <- function(x = matrix()) { 
  ## initialize the value of the matrix inverse to NULL
  matrixinverse <- NULL                     
  ## delcare another function set where the value will be cached in 1. Matrix is created
  ## for the first time. 2. changes made to cached matrix
  set <- function(y) {                      
    x <<- y
    ## change the value …Run Code Online (Sandbox Code Playgroud) 我已经使用 Tkinter 创建了一个具有不同菜单选项的 GUI(下面生成了一个类似的示例)。每个菜单都有不同的命令,单击这些命令会创建一个新框架。现在发生的情况是,如果我切换到不同的命令,新帧将堆叠在当前帧下方,而不是替换旧帧。
我想知道前进的最佳方式是什么。
import Tkinter as tkinter
root = tkinter.Tk()
root.minsize(400,300)
welcome = tkinter.Frame(root).grid()
label = tkinter.Label(welcome, text="Welcome to my program").grid(row=0, column=3)
button = tkinter.Button(welcome,text="Exit",command=root.destroy).grid(row=3, column=1)
def newFrame():
newFrame = tkinter.Frame(root).grid()
newFrame_name = tkinter.Label(newFrame, text="This is another frame").grid()
menu = tkinter.Menu(root)
root.config(menu=menu)
main_menu = tkinter.Menu(menu)
menu.add_cascade(label="Main Menu", menu= main_menu)
main_menu.add_command(label="New Frame", command=newFrame)
main_menu.add_command(label="Another Frame", command=newFrame)
#menu.add_command(label="Exit", command=root.destroy, menu= filemenu)
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
现在,如果我在新框架和另一个框架之间切换,窗口会堆叠起来,但我希望一个窗口替换另一个。
有任何想法吗?谢谢。