scikit学习平均感知器分类器(scikit learn averaged perceptron classifier)

我是机器学习的新学习者,我想做一个只有少数属性的2级分类。 我通过在线研究得知,两类平均感知器算法适用于线性模型的两类分类。

但是,我一直在阅读Scikit-learn的文档,如果Scikit-learn提供了一个平均的感知器算法,我有点困惑。

我想知道sklearn.linear_model.Perceptron类是否可以通过正确设置参数来实现为两级平均感知器算法。

非常感谢你的帮助。


I am a new learner to machine learning and I want to do a 2-class classification with only a few attributes. I have learned by researching online that two-class averaged perceptron algorithm is good for two-class classification with a linear model.

However, I have been reading through the documentation of Scikit-learn, and I am a bit confused if Scikit-learn is providing a averaged perceptron algorithm.

I wonder if the sklearn.linear_model.Perceptron class can be implemented as the two-class averaged perceptron algorithm by setting up the parameters correctly.

I appreciate it very much for your kind help.


原文:https://stackoverflow.com/questions/47665910
2023-02-21 16:02

满意答案

您只需执行以下操作:准备好您的xml,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent" >

  <EditText
     android:id="@+id/editText"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_alignParentTop="true"
     android:layout_toLeftOf="@+id/addItem"
     android:hint="Add a new item to List View" />

  <Button
     android:id="@+id/addItem"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentRight="true"
     android:text="Add" /> 

  <ListView
     android:id="@+id/listView"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_below="@+id/editText" >
  </ListView>

</RelativeLayout>

活动如下所示:

public class MainActivity extends Activity {
    EditText editText;
    Button addButton;
    ListView listView;
    ArrayList<String> listItems;
    ArrayAdapter<String> adapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        editText = (EditText) findViewById(R.id.editText);
        addButton = (Button) findViewById(R.id.addItem);
        listView = (ListView) findViewById(R.id.listView);
        listItems = new ArrayList<String>();
        listItems.add("First Item - added on Activity Create");
        adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, listItems);
        listView.setAdapter(adapter);
        addButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                listItems.add(editText.getText().toString());
                adapter.notifyDataSetChanged();
            }
        });
        listView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> a, View v, int position,
                    long id) {
                Toast.makeText(MainActivity.this, "Clicked", Toast.LENGTH_LONG)
                        .show();
            }
        });
    }
}

You just do the following : Prepare your xml like this :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent" >

  <EditText
     android:id="@+id/editText"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_alignParentTop="true"
     android:layout_toLeftOf="@+id/addItem"
     android:hint="Add a new item to List View" />

  <Button
     android:id="@+id/addItem"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentRight="true"
     android:text="Add" /> 

  <ListView
     android:id="@+id/listView"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_below="@+id/editText" >
  </ListView>

</RelativeLayout>

Activity looks like following :

public class MainActivity extends Activity {
    EditText editText;
    Button addButton;
    ListView listView;
    ArrayList<String> listItems;
    ArrayAdapter<String> adapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        editText = (EditText) findViewById(R.id.editText);
        addButton = (Button) findViewById(R.id.addItem);
        listView = (ListView) findViewById(R.id.listView);
        listItems = new ArrayList<String>();
        listItems.add("First Item - added on Activity Create");
        adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, listItems);
        listView.setAdapter(adapter);
        addButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                listItems.add(editText.getText().toString());
                adapter.notifyDataSetChanged();
            }
        });
        listView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> a, View v, int position,
                    long id) {
                Toast.makeText(MainActivity.this, "Clicked", Toast.LENGTH_LONG)
                        .show();
            }
        });
    }
}

相关问答

更多

添加按钮到自定义ListView适配器(Adding button to custom ListView Adapter)

首先为您的数据model一个model public class DataModel { String title; String description; String addedby; public DataModel(String title, String description, String addedby) { this.title=title; this.description=description; ...

在将按钮添加到xml文件时,使用自定义适配器的ListView也会被覆盖(ListView using custom Adapter is overwritten when also adding buttons to the xml file)

当您在第一个layout中添加buttons ,该布局将您的listview layout推向左侧,这就是为什么您无法看到您的list 。 尝试使用relativeLayout或正确地放置您的linearLayout 。 我已经使用了RelativeLayout ,它现在工作正常: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"...

按钮上的自定义适配器刷新ListView单击(Refreshing ListView from Custom Adapter on Button Click)

更新数据后,只需在click事件中调用notifyDataSetChanged() 。 upvote.setOnClickListener( //in here new View.OnClickListener(){ public void onClick(View v){ comments.get(position)[1] = Integer.toString(Integer.parseInt(com...

如何在适配器的listview项目中单击图像按钮后刷新列表视图?(How to refresh listview after click imagebutton in listview item from adapter?)

简单调用notifyDataSetChanged(); 当您单击按钮以刷新ListView buttonHeart.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { ... notifyDataSetChanged(); } }); Simple call notifyDataSetChanged(); w...

ListView适配器行为奇怪(ListView adapter behaves strangely)

如果convertView == null,请尝试获取视图状态 if (convertView == null) { holder = new Holder(); convertView = mInflator.inflate(R.layout.row_viewproduct, null); convertView.setTag(holder); } else { holder = (...

无法单击Listview适配器的按钮(Listview adapter's button can not be clicked)

尝试将android:focusable和android:focusableInTouchMode为false为您的按钮: <Button android:id="@+id/btn_like" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" ...

ListView适配器表现得很奇怪。(ListView Adapter behaving weirdly. Unrelated buttons in the ListView get clicked after i click on a button in the same ListView)

单击按钮时,将禁用一个Button 。 然后,当您滚动时,该Button将被回收并被其他项目重用。 你永远不会重新启用那个Button ,所以过了一会儿,上下滚动,你的所有Button都将被禁用。 这不是正确的方法。 您无法根据用户执行的某些操作(例如单击按钮)在任何View进行更改,因为ListView的View都会被回收并重复用于不同的列表项。 当用户采取某些操作时,您需要更改数据 。 在getView()您需要使用数据来设置View的状态。 在你的情况下,你可以做这样的事情: 添加一个pri...

如何使用适配器在按钮单击上添加ListView项目(How to add ListView items on button click using adapter)

您只需执行以下操作:准备好您的xml,如下所示: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="mat...

在按钮的onclicklistener中设置listview的适配器后,Listview的项目变灰了......?(Listview's items grayed out after setting the listview's adapter in a button's onclicklistener…?)

您不必在“活动”中使用getApplicationContext() 。 使用this或YourActivity.this 。 getBaseContext() - 获取当前活动的上下文(但您应该使用Context),并在活动被销毁时销毁 getApplicationContext()` - app全局上下文,对于整个生命周期中的所有活动都是相同的。 如果要为视图设置适配器,请使用活动的上下文,如YourActivity.this ( baseContext可以解决问题,但Google不建议使用它...

使用SimpleCursorAdapter更新ListView(无需重新初始化适配器)(Updating ListView using SimpleCursorAdapter ( without re-initializing adapter ))

回答自己的问题。 通过调用changeCursor()方法获得此问题的解决方案。 public void saveButton(View view){ EditText editText = (EditText) findViewById(R.id.edit_text); String data = editText.getText().toString(); database.insertData(data); Log.v("database",databas...

相关文章

更多

learn C on the mac 读后笔记

phper 学习c的一点笔记。参考资料learn C on the mac 图书地址--http:// ...

10 Programming Languages You Should Learn Right Now

By Deborah Rothberg September 15, 2006 Knowing a ...

Solr学习笔记之5、Component(组件)与Handler(处理器)学习

Solr学习笔记之5、Component(组件)与Handler(处理器)学习 一、搜索篇 拼写检查( ...

JAVA设计模式学习12——装饰器模式

装饰(Decorator)模式属于设计模式里的结构模式,通过装饰类动态的给一个对象添加一些额外的职责。 ...

Mangos模拟器综合资源贴

[ post] Mangos服务器配置文件中文说明 #Mangosd.conf, 适用于芒果服务器 2 ...

Solr学习笔记之2、集成IK中文分词器

Solr学习笔记之2、集成IK中文分词器 一、下载IK中文分词器 IK中文分词器 此文IK版本:IK ...

✈工欲善其事,必先利其器✔™

附:我在GitHub上整理的一些资料 技术站点 Hacker News:非常棒的针对编程的链接聚 ...

路由器基础知识点汇总学习

一、路由器配置途径   可以通过以下几个途径来配置路由器:   1. 用主控Console口接终端 ...

机器学习资源大全【转】

本文汇编了一些机器学习领域的框架、库以及软件(按编程语言排序)。 C++ 计算机视觉 CCV—基于 ...

Hadoop中的排序器/组合器/合并器

目前,海量数据处理主要存在二个问题:大规模计算(cpu+mem)、海量数据存储(disk),而Hado ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本