输入数据类型为sklearn SVD fit_transform函数(Input data type for sklearn SVD fit_transform function)
我已经在CSV文件中处理了文档数据,我在pandas DataFrame中读到了这个文件:
+----------+------+------------+ | document | term | count | +----------+------+------------+ | 1 | 126 | 1 | | 1 | 80 | 1 | | 1 | 1221 | 2 | | 2 | 2332 | 1 |
所以它由document_id,term和term frequency组成。
我没有原始文档,只有这个处理过的数据,我想用sklearn应用SVD,但我无法想象如何为SVD fit_transform()准备这个DataFrame,它期望:
X:{array-like,sparse matrix},shape(n_samples,n_features)
I have already processed document data in CSV file, which I read in pandas DataFrame:
+----------+------+------------+ | document | term | count | +----------+------+------------+ | 1 | 126 | 1 | | 1 | 80 | 1 | | 1 | 1221 | 2 | | 2 | 2332 | 1 |
So it consists of document_id, term, and term frequency.
I don't have original documents, but just this processed data, and I want to apply SVD with sklearn, but I can not figure how to prepare this DataFrame for SVD fit_transform(), which expects:
X : {array-like, sparse matrix}, shape (n_samples, n_features)
原文:https://stackoverflow.com/questions/39393994
最满意答案
改为使用URL和URLRequest:
let url = URL(string: "https://facebook.com")! webView.load(URLRequest(url: url))
这与https://stackoverflow.com/a/37812485/2227743非常相似:您要么使用NSURL,而必须将其作为URL下载,否则您直接使用新的Swift 3结构。
如果您按照错误消息,您的示例将变为:
let url = NSURL(string: "https://facebook.com")! webView.load(URLRequest(url: url as URL))
它可能更糟糕:
let url = NSURL(string: "https://facebook.com")! webView.load(NSURLRequest(url: url as URL) as URLRequest)
所有这些工作,但当然它是更好的开始在Swift 3中使用URL和URLRequest,而不使用所有这些向下转换。
Use URL and URLRequest instead:
let url = URL(string: "https://facebook.com")! webView.load(URLRequest(url: url))
This is quite similar to https://stackoverflow.com/a/37812485/2227743: you either use NSURL and have to downcast it as URL, or you directly use the new Swift 3 structs.
If you follow the error message, your example would become:
let url = NSURL(string: "https://facebook.com")! webView.load(URLRequest(url: url as URL))
It could be even worse:
let url = NSURL(string: "https://facebook.com")! webView.load(NSURLRequest(url: url as URL) as URLRequest)
All this works but of course it's much better to start using URL and URLRequest in Swift 3, without using all this downcasting.
相关问答
更多-
添加以下行: completionHandler(NSURLSessionAuthChallengeDisposition.UseCredential, credential) 在didReceiveAuthenticationChallenge结束时解决了这个问题。 Add the following line: completionHandler(NSURLSessionAuthChallengeDisposition.UseCredential, credential) at the end of ...
-
你必须这样使用: if let postURL = URL(string: downloadURL) { let postRequest = URLRequest(url: postURL) cell.businessPostImage.setImageWith(postURL, placeholderImage: nil, options: SDWebImageOptions.ProgressiveDownload, completed: { (imageRequest, imageRes ...
-
将“ WebKit ”框架添加到您的班级。 请参考以下代码 import UIKit import WebKit class ViewController: UITableViewController { override func viewDidLoad() { super.viewDidLoad() let myWebView:WKWebView = WKWebView(frame: CGRectMake(0, 0, UIScreen.mainScree ...
-
你想像这样初始化WKWebView (Swift 3.0): webView = WKWebView(frame: viewForEmbeddingWebView.bounds, configuration: WKWebViewConfiguration()) webView.autoresizingMask = [.flexibleWidth, .flexibleHeight] self.viewForEmbeddingWebView.addSubview(webView) You want to in ...
-
NSURLRequest和URLRequest在Swift中有什么区别?(What is the difference between NSURLRequest and URLRequest in Swift?)[2021-09-28]
URLRequest是NSURLRequest一个覆盖层,所以你认为它们本质上是一样的。 它们是不同的类,但它们旨在提供相同的功能。 NS版本更像是遗留API,是Objective-C的延续,非NS版本是'swifty'版本。 这里是苹果自己关于NSURLRequest文档的引用: Swift覆盖到Foundation框架提供了URLRequest结构,它连接到NSURLRequest类和它的可变>子类NSMutableURLRequest。 有关值类型的更多信息,请参阅使用Cocoa和Objective- ... -
你必须在dataTask{...}之后添加.resume() 。 结果,它看起来像这样: session.dataTask(with: request, completionHandler: { (data: Data?, response: URLResponse?, error: Error?) in if let data = data{ do{ let json = try JSONSerialization.jsonObject(with: data ...
-
最终设法找到解决方案: 导入UIKit导入WebKit类ViewController:UIViewController,WKNavigationDelegate,WKUIDelegate { @IBOutlet weak var webView: WKWebView! override func viewDidLoad() { webView.navigationDelegate = self webView.uiDelegate = self super.viewDidLoad( ...
-
我认为视频正在您的WKWebview后面播放,请您调试视图层次结构并发布它? 播放视频时, Xcode->Menu->Debug->View Debugging->Capture View Hierarchy 。 我尝试过一个新的swift3项目和你的代码,没有问题,这里是视图层次结构: 你可以看到,从左侧pannel,AVPlayerView在另一个UIWindow中,与WKWebView不同, 所以我猜你项目中包含WKWebView的UIWindow有一个更高的windowLevel,所以它显示在包含A ...
-
改为使用URL和URLRequest: let url = URL(string: "https://facebook.com")! webView.load(URLRequest(url: url)) 这与https://stackoverflow.com/a/37812485/2227743非常相似:您要么使用NSURL,而必须将其作为URL下载,否则您直接使用新的Swift 3结构。 如果您按照错误消息,您的示例将变为: let url = NSURL(string: "https://facebo ...
-
好吧,解决方案是添加! 在字符串格式化中的每个变量之后,为了使其成为非可选的。 let stringUrl = "\(SERVER_HOST)...\(FBUser.id!)..." Well, the solution was to add ! after each variable in the string formatting in order to make it non-optional. let stringUrl = "\(SERVER_HOST)...\(FBUser.id!)..."